AppointmentController

目录

1、 AppointmentController

1.1、 保存主页面信息

1.1.1、 //预约表

1.1.2、 维修明细表

1.1.3、 //配件明细表

1.1.4、

1.1.5、 //从某集合中删除其与另一个集合中相同的项;其实这个说简单点就是某集合中独有的元素(差集)

1.1.6、 //删除

1.1.7、 删除全部

1.1.8、 //费用明细表

1.1.9、 新增

1.1.10、 修改

1.1.11、 从某集合中删除其与另一个集合中相同的项;其实这个说简单点就是某集合中独有的元素(差集)

1.1.12、 删除全部

  1. AppointmentController 

using QXQPS.Models;

using QXQPS.Vo;

using System;

using System.Collections;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;

namespace QXQPS.Areas.MechanicsManagment.Controllers

{

    public class AppointmentController : Controller

    {

        // GET: MechanicsManagment/Appointment

        Models.QXQPEntities myModels = new Models.QXQPEntities();

    1. 保存主页面信息

        public ActionResult ListPredate(List<PW_Predate> listPredate, List<SYS_PreRepairItemDetail> listPreRepairItem,List<SYS_PreProductDetail> listPreProduct,

          List<SYS_PreOtherCostDetail> listPreOtherCost )//

        {

            var PredateID = 0;

            try

            {

      1.                 //预约表

                if (listPredate[0].PredateID == 0)

                {

                    myModels.PW_Predate.Add(listPredate[0]);

                }

                else

                {

                    myModels.Entry(listPredate[0]).State = System.Data.Entity.EntityState.Modified;

                }

                if (myModels.SaveChanges() > 0)

                {

                    PredateID = listPredate[0].PredateID;

                    if (listPreRepairItem != null)

                    {   //

      1. 维修明细表

                        List<int> oldID = new List<int>();//原来ID

                        List<int> newID = new List<int>();//新ID

                        List<int> listdelectID = new List<int>();//需要删除的ID集合

                        var list = myModels.SYS_PreRepairItemDetail.Where(m => m.PredateID == PredateID).Select(m => new { m.PreRepairItemDetailID }).ToList();

                        foreach (var item in list)

                        {

                            oldID.Add(item.PreRepairItemDetailID);

                        }

                        for (int i = 0; i < listPreRepairItem.Count; i++)

                        {

                            listPreRepairItem[i].PredateID = PredateID;

                            if (listPreRepairItem[i].PreRepairItemDetailID == 0)

                            {

                                myModels.SYS_PreRepairItemDetail.Add(listPreRepairItem[i]);//新增

                            }

                            else

                            {

                                newID.Add(listPreRepairItem[i].PreRepairItemDetailID);

                                myModels.Entry(listPreRepairItem[i]).State = System.Data.Entity.EntityState.Modified;//修改

                            }

                        }

                        listdelectID = oldID.Except(newID).ToList();//从某集合中删除其与另一个集合中相同的项;其实这个说简单点就是某集合中独有的元素(差集)

                        foreach (var item in listdelectID)

                        {

                            var listdelect = myModels.SYS_PreRepairItemDetail.Where(m => m.PreRepairItemDetailID == item).Single();//删除

                            myModels.SYS_PreRepairItemDetail.Remove(listdelect);

                        }

                    }

                    else {

                        var listdelect = myModels.SYS_PreRepairItemDetail.Where(m => m.PredateID == PredateID).ToList();//删除全部

                        myModels.SYS_PreRepairItemDetail.RemoveRange(listdelect);

                    }

                    if (listPreProduct != null)

                    {

      1.                         //配件明细表

                        List<int> oldID = new List<int>();//原来ID

                        List<int> newID = new List<int>();//新ID

                        List<int> listdelectID = new List<int>();//需要删除的ID集合

                        var list = myModels.SYS_PreProductDetail.Where(m => m.PredateID == PredateID).Select(m => new { m.PreProductDetailID }).ToList();

                        foreach (var item in list)

                        {

                            oldID.Add(item.PreProductDetailID);

                        }

                        for (int i = 0; i < listPreProduct.Count; i++)

                        {

                            listPreProduct[i].PredateID = PredateID;

                            if (listPreProduct[i].PreProductDetailID == 0)

                            {

                                myModels.SYS_PreProductDetail.Add(listPreProduct[i]);//新增

                            }

                            else

                            {

                                newID.Add(listPreProduct[i].PreProductDetailID);

                                myModels.Entry(listPreProduct[i]).State = System.Data.Entity.EntityState.Modified;//修改

                            }

                        }

                        listdelectID = oldID.Except(newID).ToList();

      1. //从某集合中删除其与另一个集合中相同的项;其实这个说简单点就是某集合中独有的元素(差集)

                        foreach (var item in listdelectID)

                        {

                            var listdelect = myModels.SYS_PreProductDetail.Where(m => m.PreProductDetailID == item).Single();

      1. //删除

                            myModels.SYS_PreProductDetail.Remove(listdelect);

                        }

                    }

                    else

                    {

                        var listdelect = myModels.SYS_PreProductDetail.Where(m => m.PredateID == PredateID).ToList();//

      1. 删除全部

                        myModels.SYS_PreProductDetail.RemoveRange(listdelect);

                    }

                    if (listPreOtherCost != null)

                    {

      1.                         //费用明细表

                        List<int> oldID = new List<int>();//原来ID

                        List<int> newID = new List<int>();//新ID

                        List<int> listdelectID = new List<int>();//需要删除的ID集合

                        var list = myModels.SYS_PreOtherCostDetail.Where(m => m.PredateID == PredateID).Select(m => new { m.PreOtherCostDetailID }).ToList();

                        foreach (var item in list)

                        {

                            oldID.Add(item.PreOtherCostDetailID);

                        }

                        for (int i = 0; i < listPreOtherCost.Count; i++)

                        {

                            listPreOtherCost[i].PredateID = PredateID;

                            if (listPreOtherCost[i].PreOtherCostDetailID == 0)

                            {

                                myModels.SYS_PreOtherCostDetail.Add(listPreOtherCost[i]);//

      1. 新增

                            }

                            else

                            {

                                newID.Add(listPreOtherCost[i].PreOtherCostDetailID);

                                myModels.Entry(listPreOtherCost[i]).State = System.Data.Entity.EntityState.Modified;//

      1. 修改

                            }

                        }

                        listdelectID = oldID.Except(newID).ToList();//

      1. 从某集合中删除其与另一个集合中相同的项;其实这个说简单点就是某集合中独有的元素(差集)

                        foreach (var item in listdelectID)

                        {

                            var listdelect = myModels.SYS_PreOtherCostDetail.Where(m => m.PreOtherCostDetailID == item).Single();//删除

                            myModels.SYS_PreOtherCostDetail.Remove(listdelect);

                        }

                    }

                    else

                    {

                        var listdelect = myModels.SYS_PreOtherCostDetail.Where(m => m.PredateID == PredateID).ToList();//

      1. 删除全部

                        myModels.SYS_PreOtherCostDetail.RemoveRange(listdelect);

                    }

                    myModels.SaveChanges();

                }

                else

                {

                    return Json(false, JsonRequestBehavior.AllowGet);

                }

            }

            catch (Exception)

            {

                return Json(false, JsonRequestBehavior.AllowGet);

            }

            return Json(PredateID, JsonRequestBehavior.AllowGet);

        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

处处清欢

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值