Ejemplo n.º 1
0
 public ActionResult Edit(HotelRoomTypeManageModel model, SubmitTypeEnums submit)
 {
     if (ModelState.IsValid)
     {
         var response = _hotelRoomTypeServices.SaveHotelRoomTypeManageModel(model);
         if (response.Success)
         {
             SetSuccessMessage(response.Message);
             switch (submit)
             {
                 case SubmitTypeEnums.Save:
                     return RedirectToAction("Index");
                 default:
                     return RedirectToAction("Edit", new { id = model.Id });
             }
         }
         SetErrorMessage(response.Message);
     }
     model.HotelRoomTypeServices = _hotelServiceServices.GetHotelRoomServices(model.Id);
     return View(model);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Save HotelRoomType manage model
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel SaveHotelRoomTypeManageModel(HotelRoomTypeManageModel model)
        {
            ResponseModel response;
            var hotelRoomType = GetById(model.Id);

            #region Edit HotelRoomType
            if (hotelRoomType != null)
            {
                hotelRoomType.Name = model.Name;
                hotelRoomType.Description = model.Description;
                hotelRoomType.Price = model.Price;
                hotelRoomType.RecordOrder = model.RecordOrder;

                var currentServices = hotelRoomType.HotelRoomServices.Select(rs => rs.ServiceId).ToList();
                foreach (var id in currentServices)
                {
                    if (!model.HotelRoomTypeServiceIds.Contains(id))
                    {
                        _hotelRoomServiceRepository.Delete(id);
                    }
                }
                foreach (var serviceId in model.HotelRoomTypeServiceIds)
                {
                    if (currentServices.All(n => n != serviceId))
                    {
                        var hotelRoomTypeHotelRoomTypeCategory = new HotelRoomService
                        {
                            RoomTypeId = hotelRoomType.Id,
                            ServiceId = serviceId
                        };
                        _hotelRoomServiceRepository.Insert(hotelRoomTypeHotelRoomTypeCategory);
                    }
                }

                //Get page record order
                response = Update(hotelRoomType);
                return response.SetMessage(response.Success ?
                    _localizedResourceServices.T("AdminModule:::HotelRoomTypes:::Messages:::UpdateSuccessfully:::Update HotelRoomType successfully.")
                    : _localizedResourceServices.T("AdminModule:::HotelRoomTypes:::Messages:::UpdateFailure:::Update HotelRoomType failed. Please try again later."));
            }
            #endregion

            hotelRoomType = new HotelRoomType
            {
                Name = model.Name,
                Description = model.Description,
                Price = model.Price,
            };

            response = Insert(hotelRoomType);
            foreach (var serviceId in model.HotelRoomTypeServiceIds)
            {
                var hotelRoomTypeHotelRoomTypeCategory = new HotelRoomService
                {
                    RoomTypeId = hotelRoomType.Id,
                    ServiceId = serviceId
                };
                _hotelRoomServiceRepository.Insert(hotelRoomTypeHotelRoomTypeCategory);
            }
            return response.SetMessage(response.Success ?
                _localizedResourceServices.T("AdminModule:::HotelRoomTypes:::Messages:::CreateSuccessfully:::Create HotelRoomType successfully.")
                : _localizedResourceServices.T("AdminModule:::HotelRoomTypes:::Messages:::CreateFailure:::Create HotelRoomType failed. Please try again later."));
        }