コード例 #1
0
 public SuperSuit CreateSuperSuit(SuperSuit superSuit)
 {
     if (superSuit.Price > 0)
     {
         return(_superSuitShopRepository.CreateSuperSuit(superSuit));
     }
     else
     {
         throw new InvalidDataException("To create SuperSuit you need a Price");
     }
 }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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}"));
            }
        }
コード例 #5
0
        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);
        }
コード例 #6
0
 public ActionResult <SuperSuit> Post([FromBody] SuperSuit superSuit)
 {
     return(_superSuitService.CreateSuperSuit(superSuit));
 }
コード例 #7
0
 public SuperSuit UpdateSuperSuit(SuperSuit superSuit)
 {
     return(_superSuitShopRepository.UpdateSuperSuit(superSuit));
 }
コード例 #8
0
 public ActionResult <SuperSuit> Put(int id, [FromBody] SuperSuit superSuit)
 {
     return(_superSuitService.UpdateSuperSuit(id));
 }
コード例 #9
0
 public SuperSuit CreateSuperSuit(SuperSuit superSuit)
 {
     return(_superSuitRepository.CreateSuperSuit(superSuit));
 }
コード例 #10
0
 public SuperSuit CreateSuperSuit(SuperSuit superSuit)
 {
     _ctx.Attach(superSuit).State = EntityState.Added;
     _ctx.SaveChanges();
     return(superSuit);
 }