public IActionResult AddItem([FromBody] ItemAddModel item) { userInformation.ThrowErrorIfNotLoggedIn(); return(base.Ok(service.AddItem(new PantryItem { // Name = item.Name, Quantity = new Quantity { Amount = item.Amount, Unit = item.MeasurementUnit }, BuyDate = item.BuyDate, ExpirationDate = item.ExpirationDate })));; }
public async Task <IActionResult> Add([FromBody] ItemAddModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorList())); } try { await _manager.AddAsync(model); } catch (Exception ex) { return(BadRequest(ex.Message)); } return(Ok()); }
public static Item Create(ItemAddModel model, string userId) { var item = new Item { Name = model.Name, Rate = model.Rate, Description = model.Description, IsTaxable = model.IsTaxable?.Equals("1") ?? false, SalesTaxId = model.SalesTaxId, Status = Constants.RecordStatus.Active, CreatedBy = userId ?? "0", CreatedOn = Utility.GetDateTime(), isForSell = model.isForSell?.Equals("1") ?? false, BankAccountId = model.BankAccountId }; return(item); }
public async Task AddAsync(ItemAddModel model) { await _repository.AddAsync(ItemFactory.Create(model, _userId)); await _unitOfWork.SaveChangesAsync(); }