public async Task <IActionResult> GPSFormPartial([FromBody] DeviceModel device) { try { UserDetailModel user = HttpContext.Session.SessionGet <UserDetailModel>("user"); if (user == null) { return(PartialView("_ErrorPartial", new ErrorViewModel { ErrorMessage = "Session expired. Please login to continue.", ErrorCode = 1 })); } GPSDeviceViewModel GPSViewModel = new GPSDeviceViewModel(device); GPSViewModel.Lines.AddRange(GlobalHelpers.GenerateSelectListForLines(await _lineRepository.GetLines(user.ID), GPSViewModel.DevicePHP)); GPSViewModel.Drivers.AddRange(GlobalHelpers.GenerateSelectListForDrivers(await _driverRepository.GetDrivers(user.ID))); return(PartialView(GPSViewModel)); } catch (Exception ex) { return(PartialView("_ErrorPartial", new ErrorViewModel { ErrorMessage = ex.GetBaseException().Message, ErrorCode = 2 })); } }
// GET: GPSDevices public ActionResult Index(int?id) { GPSDeviceViewModel gpsDeviceViewModel = new GPSDeviceViewModel(); if (id != null) { GPSDevice gpsDevice = gpsDeviceService.GetGPSDeviceById(id); gpsDeviceViewModel = new GPSDeviceViewModel() { Id = gpsDevice.Id, IsActive = gpsDevice.IsActive, ModelNumber = gpsDevice.Model, SerialNumber = gpsDevice.SerialNumber, SupplierName = gpsDevice.Supplier.Name }; } ViewBag.SupplierList = new SelectList(genericService.GetList <Supplier>(), "Id", "Name"); return(View(gpsDeviceViewModel)); }
public ActionResult SaveOrUpdate(GPSDeviceViewModel model) { string newData = string.Empty, oldData = string.Empty; try { int id = model.Id; GPSDevice gpsDevice = null; GPSDevice oldGPSDevice = null; if (model.Id == 0) { gpsDevice = new GPSDevice { Model = model.ModelNumber, SerialNumber = model.SerialNumber, IsActive = true, SupplierId = model.SupplierId }; oldGPSDevice = new GPSDevice(); oldData = new JavaScriptSerializer().Serialize(oldGPSDevice); newData = new JavaScriptSerializer().Serialize(gpsDevice); } else { gpsDevice = genericService.GetList <GPSDevice>().Where(o => o.Id == model.Id).FirstOrDefault(); oldGPSDevice = genericService.GetList <GPSDevice>().Where(o => o.Id == model.Id).FirstOrDefault(); oldData = new JavaScriptSerializer().Serialize(new GPSDevice() { Id = oldGPSDevice.Id, SerialNumber = oldGPSDevice.SerialNumber, IsActive = oldGPSDevice.IsActive, SupplierId = model.SupplierId }); gpsDevice.SerialNumber = model.SerialNumber; gpsDevice.Model = model.ModelNumber; bool Example = Convert.ToBoolean(Request.Form["IsActive.Value"]); gpsDevice.IsActive = model.IsActive; gpsDevice.SupplierId = model.SupplierId; newData = new JavaScriptSerializer().Serialize(new GPSDevice() { Id = gpsDevice.Id, SerialNumber = gpsDevice.SerialNumber, IsActive = gpsDevice.IsActive }); } genericService.SaveOrUpdate <GPSDevice>(gpsDevice, gpsDevice.Id); //CommonService.SaveDataAudit(new DataAudit() //{ // Entity = "GPSDevices", // 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", "GPSDevice")); }