public async Task <IHttpActionResult> Post(SideModel side) { try { if (ModelState.IsValid) { var sideToUpdate = _repo.GetSideById(side.SideId).Result; if (sideToUpdate != null) { sideToUpdate.Description = side.Description; sideToUpdate.CategoryId = side.CategoryId; sideToUpdate.Price = side.Price; sideToUpdate.Active = side.Active; if (_repo.SaveChanges()) { return(Ok(sideToUpdate)); } } else { var mapped = _mapper.Map <Side>(side); _repo.AddSide(mapped); if (await _repo.SaveChangesAsync()) { return(Created("GetSides", mapped)); } } } } catch (Exception ex) { return(BadRequest(ex.Message)); } return(BadRequest()); }
public async Task <IActionResult> PutSide(Guid id, [FromBody] SideModel model) { var side = new SideModel() { Id = id, Name = model.Name, RackId = model.RackId, }; try { _context.Entry(side).State = EntityState.Modified; await _context.SaveChangesAsync(); return(Ok(side)); } catch (Exception ex) { throw ex; } }
//POST : /api/Warehouse/side/post public async Task <Object> PostSide(SideModel model) { var side = new SideModel() { Id = Guid.NewGuid(), Name = model.Name, RackId = model.RackId }; try { var result = await _context.Side.AddAsync(side); await _context.SaveChangesAsync(); return(Ok(side)); } catch (Exception ex) { throw ex; } }
/// <summary> /// Method to create side using parameters such as name, quantity and price. /// </summary> /// <param name="name"></param> /// <param name="quantity"></param> /// <param name="price"></param> /// <returns>A side object with full properties.</returns> public static SideModel CreateSide(string name, int quantity, decimal price) { SideModel s = new SideModel(); s.Name = name; s.Quantity = quantity; if (name == "Spicy Chicken Wings") { s.Price += (decimal)(quantity / 10 * 6.00); if (quantity % 10 == 5) { s.Price += 3.50m; } } else { s.Price += price * quantity; } return(s); }