示例#1
0
        public BaseResponse <bool> Update(HotelUpdateModel model)
        {
            try
            {
                //Return badRequest if model null
                if (model == null)
                {
                    return(BaseResponse <bool> .BadRequest());
                }
                var hotel = _db.Hotels.FirstOrDefault(k => k.Id == model.Id && !k.Deleted);
                if (hotel == null)
                {
                    return(BaseResponse <bool> .BadRequest());
                }

                //Update hotel
                hotel.InjectFrom(model);
                hotel.LastModifiedDate = DateTime.Now.Date;
                hotel.LastModifiedBy   = UserContextHelper.UserId;
                _db.Hotels.Update(hotel);
                _db.SaveChanges();
                return(BaseResponse <bool> .Success(true));
            }
            catch (Exception ex)
            {
                return(BaseResponse <bool> .InternalServerError(ex));
            }
        }
        public IActionResult Update(int id, [FromBody] HotelUpdateModel model)
        {
            var hotelChecker  = _hotelService.FindHotel(id);
            var currentUserId = int.Parse(User.Identity.Name);

            if (currentUserId != hotelChecker.User.Id && !User.IsInRole("Admin"))
            {
                return(Forbid());
            }

            var hotel = _mapper.Map <Hotel>(model);

            hotel.Id = id;
            try
            {
                // update facility
                _hotelService.Update(hotel);
                return(Ok("Successfully updated"));
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                return(BadRequest(new { message = ex.Message }));
            }
        }
示例#3
0
        public IActionResult Update([FromBody] HotelUpdateModel model, string id)
        {
            var hotelIdDecrypted = Terminator.DecryptToInt32(id);

            if (hotelIdDecrypted != 0)
            {
                model.Id = hotelIdDecrypted;
                var response = _hotelService.Update(model);
                return(Ok(response));
            }
            return(Ok(BaseResponse <bool> .BadRequest()));
        }