示例#1
0
        public ActionResult EditTypeRoom(Guid Id)
        {
            var typeRoom = _typeRoomSevice.Get(Id);

            if (typeRoom == null)
            {
                TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel
                {
                    Message     = LocalizationService.GetResourceString("Errors.NoFindTypeRoom"),
                    MessageType = GenericMessages.warning
                };

                return(RedirectToAction("TypeRoom"));
            }

            var viewModel = new AdminTypeRoomEditViewModel
            {
                Id     = typeRoom.Id,
                Name   = typeRoom.Name,
                IsShow = typeRoom.IsShow,
                Note   = typeRoom.Note
            };

            return(View(viewModel));
        }
示例#2
0
        public ActionResult NewTypeRoom()
        {
            var viewModel = new AdminTypeRoomEditViewModel
            {
                IsShow = true
            };


            return(View(viewModel));
        }
示例#3
0
        public ActionResult EditTypeRoom(AdminTypeRoomEditViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
                {
                    var typeRoom = _typeRoomSevice.Get(viewModel.Id);
                    if (typeRoom == null)
                    {
                        TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel
                        {
                            Message     = LocalizationService.GetResourceString("Errors.NoFindTypeRoom"),
                            MessageType = GenericMessages.warning
                        };

                        return(RedirectToAction("TypeRoom"));
                    }

                    typeRoom.Name   = viewModel.Name;
                    typeRoom.IsShow = viewModel.IsShow;
                    typeRoom.Note   = viewModel.Note;
                    try
                    {
                        _typeRoomSevice.Update(typeRoom);

                        unitOfWork.Commit();
                    }
                    catch (Exception ex)
                    {
                        LoggingService.Error(ex.Message);
                        unitOfWork.Rollback();

                        TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel
                        {
                            Message     = LocalizationService.GetResourceString("Error.TypeRoomEditError"),
                            MessageType = GenericMessages.warning
                        };
                    }
                }
            }

            return(View(viewModel));
        }
示例#4
0
        public ActionResult NewTypeRoom(AdminTypeRoomEditViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
                {
                    try
                    {
                        var typeRoom = new TypeRoom
                        {
                            Name   = viewModel.Name,
                            IsShow = viewModel.IsShow,
                            Note   = viewModel.Note
                        };

                        _typeRoomSevice.Add(typeRoom);

                        // We use temp data because we are doing a redirect
                        TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel
                        {
                            Message     = "Type Room Created",
                            MessageType = GenericMessages.success
                        };
                        unitOfWork.Commit();

                        return(RedirectToAction("TypeRoom"));
                    }
                    catch (Exception)
                    {
                        unitOfWork.Rollback();

                        ModelState.AddModelError("", "There was an error creating the Type Room");
                    }
                }
            }
            else
            {
                ModelState.AddModelError("", "There was an error creating the Type Room");
            }

            return(View(viewModel));
        }