public void Create(CreateCellarInput input) { var @entity = Cellar.Create(input.Name, input.Address, input.Phone, input.WareHouseManagerId, input.Latitude, input.Latitude, input.CreatorGuidId, _dateTime.Now, input.CostCenter, input.CompanyName); if (@entity == null) { throw new UserFriendlyException("No se pudo crear la Ubicación."); } if (_cellarManager.CellarExist(@entity.Name, input.Id, input.CompanyName)) { throw new UserFriendlyException("Existe una Ubicación con el mismo Nombre."); } _cellarRepository.Insert(@entity); }
public ActionResult Create() { CreateCellarInput viewModel = new CreateCellarInput(); try { viewModel.CompanyName = _currentUser.CompanyName; viewModel.WareHouseUsers = _cellarService.GetAllWareHouseUsers(_currentUser.CompanyName); viewModel.ErrorCode = ErrorCodeHelper.None; viewModel.ErrorDescription = ""; } catch (Exception e) { viewModel.ErrorCode = ErrorCodeHelper.Error; viewModel.ErrorDescription = "Error al obtener datos."; } return(PartialView("_createPartial", viewModel)); }
public ActionResult Create(CreateCellarInput viewModel) { try { //var currentUserId = (CustomPrincipal)HttpContext.User if (ModelState.IsValid) { //var temp = new Cellar(); //Cellar lastCellar = _cellarService.FilterBy(b => b.Active, "").OrderByDescending(b => b.NoCellar).FirstOrDefault(); //if (lastCellar != null) // viewModel.NoCellar = lastCellar.NoCellar + 1; //else // viewModel.NoCellar = 1; viewModel.CompanyName = _currentUser.CompanyName; viewModel.CreatorGuidId = _currentUser.CurrentUserId; _cellarService.Create(viewModel); ModelState.Clear(); var newVm = new CreateCellarInput(); newVm.WareHouseUsers = _cellarService.GetAllWareHouseUsers(_currentUser.CompanyName); newVm.ErrorCode = ErrorCodeHelper.Ok; newVm.ErrorDescription = "¡Ubicación guardada exitosamente!"; return(PartialView("_createPartial", newVm)); //return Json(newVm, JsonRequestBehavior.AllowGet); } viewModel.WareHouseUsers = _cellarService.GetAllWareHouseUsers(_currentUser.CompanyName); viewModel.ErrorCode = ErrorCodeHelper.Error; viewModel.ErrorDescription = "Error al intentar guardar los datos."; return(PartialView("_createPartial", viewModel)); } catch (Exception e) { viewModel.WareHouseUsers = _cellarService.GetAllWareHouseUsers(_currentUser.CompanyName); viewModel.ErrorCode = ErrorCodeHelper.Error; viewModel.ErrorDescription = e.Message; return(PartialView("_createPartial", viewModel)); } }