Пример #1
0
        public JsonResult Manage(HotelRoomModel model, GridManagingModel manageModel)
        {
            if (ModelState.IsValid || manageModel.Operation == GridOperationEnums.Del)
            {
                return Json(_hotelRoomServices.ManageHotelRoom(manageModel.Operation, model));
            }

            return Json(new ResponseModel
            {
                Success = false,
                Message = GetFirstValidationResults(ModelState).Message
            });
        }
Пример #2
0
        /// <summary>
        /// Manage Site HotelRoom
        /// </summary>
        /// <param name="operation">the operation</param>
        /// <param name="model">the HotelRoom model</param>
        /// <returns></returns>
        public ResponseModel ManageHotelRoom(GridOperationEnums operation, HotelRoomModel model)
        {
            int hotelRoomTypeId;
            ResponseModel response;
            Mapper.CreateMap<HotelRoomModel, HotelRoom>();
            HotelRoom hotelRoom;
            switch (operation)
            {
                case GridOperationEnums.Edit:
                    hotelRoom = GetById(model.Id);
                    hotelRoom.Name = model.Name;
                    hotelRoom.Note = model.Note;
                    hotelRoom.Status = model.Status;
                    if (int.TryParse(model.HotelRoomTypeName, out hotelRoomTypeId))
                    {
                        hotelRoom.HotelRoomTypeId = hotelRoomTypeId;
                    }

                    response = Update(hotelRoom);
                    return response.SetMessage(response.Success ?
                        _localizedResourceServices.T("AdminModule:::HotelRooms:::Messages:::UpdateSuccessfully:::Update room successfully.")
                        : _localizedResourceServices.T("AdminModule:::HotelRooms:::Messages:::UpdateFailure:::Update room failed. Please try again later."));

                case GridOperationEnums.Add:
                    hotelRoom = Mapper.Map<HotelRoomModel, HotelRoom>(model);
                    hotelRoom.Status = model.Status;
                    if (int.TryParse(model.HotelRoomTypeName, out hotelRoomTypeId))
                    {
                        hotelRoom.HotelRoomTypeId = hotelRoomTypeId;
                    }

                    response = Insert(hotelRoom);
                    return response.SetMessage(response.Success ?
                        _localizedResourceServices.T("AdminModule:::HotelRooms:::Messages:::CreateSuccessfully:::Create room successfully.")
                        : _localizedResourceServices.T("AdminModule:::HotelRooms:::Messages:::CreateFailure:::Insert room failed. Please try again later."));

                case GridOperationEnums.Del:
                    response = Delete(model.Id);
                    return response.SetMessage(response.Success ?
                        _localizedResourceServices.T("AdminModule:::HotelRooms:::Messages:::DeleteSuccessfully:::Delete room successfully.")
                        : _localizedResourceServices.T("AdminModule:::HotelRooms:::Messages:::DeleteFailure:::Delete room failed. Please try again later."));
            }
            return new ResponseModel
            {
                Success = false,
                Message = _localizedResourceServices.T("AdminModule:::HotelRooms:::Messages:::ObjectNotFounded:::Room is not founded.")
            };
        }