Пример #1
0
        public ActionResult Update(CycleEventFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Types = _unitOfWork.Types.GetEventTypes();
                return(View("CycleEventForm", viewModel));
            }

            var userId     = User.Identity.GetUserId();
            var cycleEvent = _unitOfWork.CycleEvents.GetCycleEvent(viewModel.Id);

            if (cycleEvent == null)
            {
                return(HttpNotFound());
            }

            if (cycleEvent.UserId != userId)
            {
                return(new HttpUnauthorizedResult());
            }

            var periodEvents = _unitOfWork.CycleEvents.GetPeriodEvents(userId);
            var days         = viewModel.Type == 1 ? DateCalculations.GetDaysToCalculate(periodEvents) : 0;

            cycleEvent.Modify(viewModel.GetStartDate(), viewModel.GetEndDate(days), viewModel.Type);

            _unitOfWork.Complete();

            return(RedirectToAction("GetRecentEvents", "CycleEvents"));
        }
Пример #2
0
        public ActionResult Create(CycleEventFormViewModel viewModel)
        {
            var userId = User.Identity.GetUserId();

            if (!ModelState.IsValid)
            {
                viewModel.Types = _unitOfWork.Types.GetEventTypes();
                return(View("CycleEventForm", viewModel));
            }

            var periodEvents = _unitOfWork.CycleEvents.GetPeriodEvents(userId);
            var days         = viewModel.Type == 1 ? DateCalculations.GetDaysToCalculate(periodEvents) : 0;

            var cycleEvent = new Event()
            {
                StartDate = viewModel.GetStartDate(),
                EndDate   = viewModel.GetEndDate(days),
                TypeId    = viewModel.Type,
                UserId    = userId
            };

            _unitOfWork.CycleEvents.Add(cycleEvent);
            _unitOfWork.Complete();

            return(RedirectToAction("GetRecentEvents", "CycleEvents"));
        }