public ActionResult Add(DeviceTypeViewModel deviceType) { if (Session["UserData"] is Admin) { if (ModelState.IsValid) { try { if (deviceType.DeviceTypeId == Guid.Empty) { deviceType.DeviceTypeId = Guid.NewGuid(); var device = Mapper.Map <DeviceTypeViewModel, DeviceType>(deviceType); // deal.parent = Guid.Parse(Request.Form["CustomerId"]); devicetypeService.CreateDeviceType(device); devicetypeService.SaveDeviceType(); } else { var device = devicetypeService.GetDeviceType(deviceType.DeviceTypeId); Mapper.Map <DeviceTypeViewModel, DeviceType>(deviceType, device); devicetypeService.UpdateDeviceType(device); devicetypeService.SaveDeviceType(); } return(Json(new { Result = "Success" })); } catch (Exception ex) { } } } return(PartialView("_Add", deviceType)); }