// GET: DepotTanks
        public ActionResult Index(int?id)
        {
            DepotTankViewModel depotViewModel = new DepotTankViewModel();

            if (id != null)
            {
                DepotTank depot = depotTankService.GetDepotTankById(id);

                depotViewModel = new DepotTankViewModel()
                {
                    Id             = depot.Id,
                    DepotId        = depot.DepotId,
                    DepotCode      = depot.Depot.Code,
                    TankId         = depot.TankId,
                    TankCode       = depot.Tank.Code,
                    SensorDeviceId = depot.SensorDeviceId,
                    SensorDeviceSN = depot.SensorDevice.SerialNumber
                };
            }

            ViewBag.DepotList        = new SelectList(depotService.GetDepotList().Select(g => new { Id = g.Id, Name = g.Code }), "Id", "Name");
            ViewBag.TankList         = new SelectList(tankService.GetTankList().Select(g => new { Id = g.Id, Name = g.Code }), "Id", "Name");
            ViewBag.SensorDeviceList = new SelectList(sensorDeviceService.GetSensorDeviceList().Select(g => new { Id = g.Id, Name = g.SerialNumber }), "Id", "Name");

            return(View(depotViewModel));
        }
 public void SaveOrUpdate(DepotTank depots)
 {
     using (FLMSEntities entities = new FLMSEntities())
     {
         if (depots.Id == 0)
         {
             entities.DepotTanks.Add(depots);
             entities.SaveChanges();
         }
         else
         {
             entities.Entry(depots).State = System.Data.Entity.EntityState.Modified;
             entities.SaveChanges();
         }
     }
 }
        public ActionResult SaveOrUpdate(DepotTank model)
        {
            string newData = string.Empty, oldData = string.Empty;

            try
            {
                int       id           = model.Id;
                DepotTank depot        = null;
                DepotTank oldDepotTank = null;
                if (model.Id == 0)
                {
                    depot = new DepotTank
                    {
                        DepotId        = model.DepotId,
                        TankId         = model.TankId,
                        SensorDeviceId = model.SensorDeviceId
                    };

                    oldDepotTank = new DepotTank();
                    oldData      = new JavaScriptSerializer().Serialize(oldDepotTank);
                    newData      = new JavaScriptSerializer().Serialize(depot);
                }
                else
                {
                    depot        = genericService.GetList <DepotTank>().Where(o => o.Id == model.Id).FirstOrDefault();
                    oldDepotTank = genericService.GetList <DepotTank>().Where(o => o.Id == model.Id).FirstOrDefault();

                    oldData = new JavaScriptSerializer().Serialize(new DepotTank()
                    {
                        Id             = oldDepotTank.Id,
                        DepotId        = model.DepotId,
                        TankId         = model.TankId,
                        SensorDeviceId = model.SensorDeviceId
                    });

                    depot.DepotId        = model.DepotId;
                    depot.TankId         = model.TankId;
                    depot.SensorDeviceId = model.SensorDeviceId;

                    newData = new JavaScriptSerializer().Serialize(new DepotTank()
                    {
                        Id             = depot.Id,
                        DepotId        = depot.DepotId,
                        TankId         = depot.TankId,
                        SensorDeviceId = depot.SensorDeviceId
                    });
                }

                genericService.SaveOrUpdate <DepotTank>(depot, depot.Id);

                //CommonService.SaveDataAudit(new DataAudit()
                //{
                //    Entity = "DepotTanks",
                //    NewData = newData,
                //    OldData = oldData,
                //    UpdatedOn = DateTime.Now,
                //    UserId = User.Identity.GetUserId()
                //});

                TempData["Message"] = ResourceData.SaveSuccessMessage;
            }
            catch (Exception ex)
            {
                TempData["Message"] = string.Format(ResourceData.SaveErrorMessage, ex.InnerException);
            }

            return(RedirectToAction("Index", "DepotTank"));
        }