Beispiel #1
0
        public IHttpActionResult Post(RentCreate rentCreate)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateRentService();

            if (!service.CreateRent(rentCreate))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
        public bool CreateRent(RentCreate model)
        {
            var entity =
                new RealEstateRent()
            {
                DateAvailable        = model.DateAvailable,
                PricePerMonth        = model.PricePerMonth,
                Description          = model.Description,
                UtilitiesIncluded    = model.UtilitiesIncluded,
                PetsAllowed          = model.PetsAllowed,
                IsRentFavorite       = model.IsRentFavorite,
                RealEstatePropertyId = model.RealEstatePropertyId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.RealEstateRent.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }