public ActionResult EditDevice(ClientDeviceInfo cdi_cl) { if (ModelState.IsValid) { using (var db = new MainDbContext()) { if (cdi_cl.deviceCategory == null) { cdi_cl.deviceCategory = TempData.Get <string>("deviceCategory"); } /* * if (cdi_cl.deviceSubcategory == null) * { * cdi_cl.deviceSubcategory = TempData.Get<string>("deviceSubcategory"); * } */ string timeToday = DateTime.Now.ToString("hh:mm:ss tt"); string dateToday = DateTime.Now.ToString("M/dd/yyyy"); // even though it's a edit date, still keep it as a registration date cdi_cl.deviceRegistrationDate = dateToday; cdi_cl.deviceRegistrationTime = timeToday; string client = GetCurrentClaimValues.GetCurrentUserClient(); int deviceAddedByUser = GetCurrentClaimValues.GetCurrentUserId(); cdi_cl.client = client; cdi_cl.deviceAddedByUser = deviceAddedByUser; db.Entry(cdi_cl).State = EntityState.Modified; db.SaveChanges(); } } else { ModelState.AddModelError("", "Incorrect data has been entered"); } if (GetCurrentClaimValues.GetCurrentUserRole() == RoleNames.ROLE_ADMIN) { return(RedirectToAction("RegisteredDevices", "Admin")); } else { return(RedirectToAction("Index", "Registrar")); } }
public ActionResult AddNewDevice(ClientDeviceInfo cdi_cl) { if (ModelState.IsValid) { using (var db = new MainDbContext()) { string timeToday = DateTime.Now.ToString("HH:mm:ss"); string dateToday = DateTime.Now.ToString("M/dd/yyyy"); string client = GetCurrentClaimValues.GetCurrentUserClient(); int deviceAddedByUser = GetCurrentClaimValues.GetCurrentUserId(); var device = db.clientDeviceInfo.Create(); device.client = client; device.deviceAddedByUser = deviceAddedByUser; device.deviceRegistrationDate = dateToday; device.deviceRegistrationTime = timeToday; // since it is an id for the purposes of cascading dropdowns //int deviceCategoryId = Convert.ToInt32(cdi_cl.deviceCategory); //var materializeDeviceCategory = db.deviceCategory.Where(c => c.deviceCategoryId == deviceCategoryId).Select(c => c.deviceCategoryName).ToList(); string deviceCategory = cdi_cl.deviceCategory; device.deviceCategory = deviceCategory; //device.deviceSubcategory = cdi_cl.deviceSubcategory; device.deviceName = cdi_cl.deviceName; device.deviceNUINTASerialNumber = cdi_cl.deviceNUINTASerialNumber; device.deviceCarrier = cdi_cl.deviceCarrier; device.deviceCondition = cdi_cl.deviceCondition; device.deviceBin = cdi_cl.deviceBin; device.deviceRepairCost = cdi_cl.deviceRepairCost; device.deviceOtherComments = cdi_cl.deviceOtherComments; // since an admin would have a slightly different view when registering a device if (GetCurrentClaimValues.GetCurrentUserRole() == RoleNames.ROLE_ADMIN) { device.deviceUsedBy = cdi_cl.deviceUsedBy; device.deviceValue = cdi_cl.deviceValue; device.deviceSoldFor = cdi_cl.deviceSoldFor; } //Console.WriteLine(device); db.clientDeviceInfo.Add(device); db.SaveChanges(); } } else { ModelState.AddModelError("", "Incorrect data has been entered"); } return(RedirectToAction("RegisteredDevices")); //if (GetCurrentClaimValues.GetCurrentUserRole() == RoleNames.ROLE_ADMIN) //{ // return RedirectToAction("Devices", "Admin"); //} //else //{ // return RedirectToAction("Index", "Registrar"); //} }