public SuperSuit CreateSuperSuit(SuperSuit superSuit) { if (superSuit.Price > 0) { return(_superSuitShopRepository.CreateSuperSuit(superSuit)); } else { throw new InvalidDataException("To create SuperSuit you need a Price"); } }
public SuperSuit NewSuperSuit(string name, string type, double price, string description) { var superSuit = new SuperSuit() { Name = name, Type = type, Price = price, Description = description }; return(superSuit); }
public SuperSuit UpdateSuperSuit(SuperSuit superSuit) { SuperSuit ss = null; try { ss = _ctx.Update(superSuit).Entity; _ctx.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); return(null); } return(ss); }
public ActionResult <SuperSuit> Put(int id, [FromBody] SuperSuit superSuit) { superSuit.Id = id; if (id < 1) { return(BadRequest("Id must be lager than zero!")); } var success = _superSuitService.UpdateSuperSuit(superSuit); if (success != null) { return(Ok(success)); } else { return(NotFound($"No Suit found with id {id}")); } }
public void CreateSuperSuitPriceMissingThrowsException() { var superSuitRepo = new Mock <ISuperSuitShopRepository>(); superSuitRepo.Setup(x => x.ReadById(It.IsAny <int>())) .Returns(new SuperSuit() { Id = 1 }); ISuperSuitShopService service = new SuperSuitShopService(superSuitRepo.Object); var superSuit = new SuperSuit() { Price = double.MinValue }; Exception ex = Assert.Throws <InvalidDataException>(() => service.CreateSuperSuit(superSuit)); Assert.Equal("To create SuperSuit you need a Price", ex.Message); }
public ActionResult <SuperSuit> Post([FromBody] SuperSuit superSuit) { return(_superSuitService.CreateSuperSuit(superSuit)); }
public SuperSuit UpdateSuperSuit(SuperSuit superSuit) { return(_superSuitShopRepository.UpdateSuperSuit(superSuit)); }
public ActionResult <SuperSuit> Put(int id, [FromBody] SuperSuit superSuit) { return(_superSuitService.UpdateSuperSuit(id)); }
public SuperSuit CreateSuperSuit(SuperSuit superSuit) { return(_superSuitRepository.CreateSuperSuit(superSuit)); }
public SuperSuit CreateSuperSuit(SuperSuit superSuit) { _ctx.Attach(superSuit).State = EntityState.Added; _ctx.SaveChanges(); return(superSuit); }