コード例 #1
0
        public ActionResult EditEvent(int id)
        {
            var viewModel = new NewCalendarEventViewModel();

            viewModel.Types = _unitOfWork.EventTypeRepository.All();
            var x = viewModel.Types.Select(r => new SelectListItem
            {
                Text  = r.Name,
                Value = r.ID.ToString()
            });

            viewModel.choices.AddRange(x);
            viewModel.Buildings = _unitOfWork.BuildingRepository.All();
            var login  = SessionHelper.GetElement <string>(SessionElement.Login);
            var user   = _unitOfWork.UserRepository.Find(login);
            var @event = _unitOfWork.CalendarEventsRepository.All().First(d => d.CalendarEventID == id);

            viewModel.ID               = @event.CalendarEventID;
            viewModel.Title            = @event.Title;
            viewModel.Description      = @event.Description;
            viewModel.StartAt          = @event.StartAt;
            viewModel.EndAt            = @event.EndAt;
            viewModel.SelectedType     = @event.EventType.ID;
            viewModel.SelectedBuilding = @event.Building.ID;
            viewModel.SelectedRoom     = @event.Room.ID;
            viewModel.Owner            = user;

            return(View(viewModel));
        }
コード例 #2
0
        public ActionResult NewEvent(NewCalendarEventViewModel viewModel)
        {
            try
            {
                var login = SessionHelper.GetElement <string>(SessionElement.Login);
                _unitOfWork.CalendarEventsRepository.Add(new CalendarEvent
                {
                    Owner       = _unitOfWork.UserRepository.Find(login),
                    StartAt     = viewModel.StartAt,
                    EndAt       = viewModel.EndAt,
                    Title       = viewModel.Title,
                    EventType   = _unitOfWork.EventTypeRepository.Find(viewModel.SelectedType),
                    Building    = _unitOfWork.BuildingRepository.Find(viewModel.SelectedBuilding),
                    Room        = _unitOfWork.RoomRepository.Find(viewModel.SelectedRoom),
                    Description = viewModel.Description
                });

                _unitOfWork.SaveChanges();
            }
            catch (Exception ex)
            {
                logger.Error(ex, ex.Message);
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(PartialView("~/Views/PartialViews/Error.cshtml", ex.Message));
            }
            return(RedirectToAction("OwnerEvent"));
        }
コード例 #3
0
        public ActionResult NewEvent()
        {
            var viewModel = new NewCalendarEventViewModel();

            viewModel.Types = _unitOfWork.EventTypeRepository.All();
            var x = viewModel.Types.Select(r => new SelectListItem
            {
                Text  = r.Name,
                Value = r.ID.ToString()
            });

            viewModel.choices.AddRange(x);
            viewModel.SelectedBuilding = 0;
            viewModel.Buildings        = _unitOfWork.BuildingRepository.All();
            return(View(viewModel));
        }
コード例 #4
0
        public ActionResult EditEvent(NewCalendarEventViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var login  = SessionHelper.GetElement <string>(SessionElement.Login);
                var user   = _unitOfWork.UserRepository.Find(login);
                var @event = _unitOfWork.CalendarEventsRepository.All().First(d => d.CalendarEventID == viewModel.ID);

                @event.Title       = viewModel.Title;
                @event.Description = viewModel.Description;
                @event.StartAt     = viewModel.StartAt;
                @event.EndAt       = viewModel.EndAt;
                @event.EventType   = _unitOfWork.EventTypeRepository.Find(viewModel.SelectedType);
                @event.Building    = _unitOfWork.BuildingRepository.Find(viewModel.SelectedBuilding);
                @event.Room        = _unitOfWork.RoomRepository.Find(viewModel.SelectedRoom);
                @event.Owner       = user;
                @event.Users.Clear();

                _unitOfWork.SaveChanges();
                return(RedirectToAction("OwnerEvent"));
            }

            return(View(viewModel));
        }