//[Authorize(Policy = PermissionsList.PermissionsIngredientAdd)] public IActionResult AddIngredient([FromBody] IngredientModel ingredientModel) { Guid ingredientId = Guid.NewGuid(); var ingredientExist = _ingredientRepository.GetIngredient(ingredientModel.Name); if (!ModelState.IsValid || ingredientExist.Result != null) { return(BadRequest()); } Ingredient ingredient = new Ingredient() { Id = ingredientId, Name = ingredientModel.Name, Quantity = ingredientModel.Quantity, Price = ingredientModel.Price, ExpirationDate = ingredientModel.ExpirationDate }; _ingredientRepository.Create(ingredient); return(Ok(new { ingredient })); }
public Task AddIngredient(IngredientModel ingredientModel) { Guid ingredientId = Guid.NewGuid(); var ingredientExist = _ingredientRepository.GetIngredient(ingredientModel.Name).Result; var ingredientsOld = _ingredientRepository.GetAll().Result; if (ingredientExist != null) { return(Clients.All.SendAsync("GetIngredients", ingredientsOld)); } Ingredient ingredient = new Ingredient() { Id = ingredientId, Name = ingredientModel.Name, Quantity = ingredientModel.Quantity, Price = ingredientModel.Price, ExpirationDate = ingredientModel.ExpirationDate }; _ingredientRepository.Create(ingredient); var ingredients = _ingredientRepository.GetAll().Result; return(Clients.All.SendAsync("GetIngredients", ingredients)); }
public async Task <Guid> AddIngredient([FromBody] IngredientModel ingredient) { await _validator.ValidateAndThrowAsync(ingredient); var mIngredient = Mapper.Map <IngredientModel, Ingredient>(ingredient); return(await _repository.Create(mIngredient)); }
public void Save() { if (Model.Id == Guid.Empty) { Model = repository.Create(Model); } else { repository.Update(Model); } }
public async Task CreateAsync(IngredientDto ingredient) { var origIngredient = _mapper.Map <IngredientDto, Ingredient>(ingredient); var ingredients = await _ingredientRepository.GetAll(); var isIngredient = ingredients.Any(d => d.Name == ingredient.Name); if (isIngredient) { throw new BadRequestException("Ingredient with the same name is exist."); } await _ingredientRepository.Create(origIngredient); }
public void Save() { if (Model.Id == Guid.Empty) { Model = ingredientRepository.Create(Model); mediator.Send(new IngredientAddedMessage { Id = Model.Id }); } else { ingredientRepository.Update(Model); mediator.Send(new IngredientUpdatedMessage { Id = Model.Id }); } Model = null; }
public async Task <IActionResult> Save(IngredientFormViewModel vm) { if (!ModelState.IsValid) { return(View("IngredientForm", vm)); } Ingredient ingredient = vm.ToIngredient(); if (vm.Id == null) { // add await _ingredientRepo.Create(ingredient); } else { // edit try { await _ingredientRepo.Update(ingredient); } catch (DbUpdateConcurrencyException) { if (!_ingredientRepo.Exists(ingredient.Id)) { return(NotFound()); } else { throw; } } } return(RedirectToAction(nameof(Index))); }
public async Task <int> Create(IngredientLogic ingredient) { return(await _ingredientRepository.Create(_mapper.Map <Ingredient>(ingredient))); }
public async Task <Either <string, int> > Handle(CreateIngredient command) => await(await Validate(command)) .Match <Task <Either <string, int> > >( async id => await _ingredientRepository.Create(new Ingredient(command.Name, command.Value)), (v) => Task.FromResult(new Either <string, int>($"Ja existe um ingrendient com id {v.Id}, cadastrado com o nome {command.Name}")) );