Exemplo n.º 1
0
        public async Task <IActionResult> Update(EventUpdateBindingModel model)
        {
            _logger.LogInformation("EventController.Update(EventUpdateBindingModel model)");

            ClaimsPrincipal currentUser = this.User;
            string          userId      = currentUser.FindFirst(ClaimTypes.NameIdentifier).Value;

            CalendarEvent ce = _unitOfWork.CalendarEvents.GetById(model.Id);

            if (ce == null)
            {
                return(NotFound());
            }

            ce.Title = model.Title;
            ce.Start = model.Start;
            ce.End   = model.End;

            ConflictCheck cc = new ConflictCheck(_unitOfWork.CalendarEvents, new OverlappingCheck());

            if (cc.DoCheck(ce))
            {
                _unitOfWork.CalendarEvents.Update(ce);
                int updated = _unitOfWork.Complete();

                if (updated > 0)
                {
                    return(new JsonResult(ce));
                }
                else
                {
                    return(base.Problem("Failed to commit."));
                }
            }
            else
            {
                return(base.Problem("Failed conflict check."));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create(EventCreateBindingModel model)
        {
            _logger.LogInformation("EventController.Create(EventCreateBindingModel model)");

            ClaimsPrincipal currentUser = this.User;
            string          userId      = currentUser.FindFirst(ClaimTypes.NameIdentifier).Value;

            CalendarEvent ce = new CalendarEvent
            {
                UserId       = userId,
                Title        = model.Title,
                Start        = model.Start,
                End          = model.End,
                DepartmentId = 1
            };

            ConflictCheck cc = new ConflictCheck(_unitOfWork.CalendarEvents, new OverlappingCheck());

            if (cc.DoCheck(ce))
            {
                _unitOfWork.CalendarEvents.Add(ce);

                int updated = _unitOfWork.Complete();

                if (updated > 0)
                {
                    return(new JsonResult(ce));
                }
                else
                {
                    return(base.Problem("Failed to commit."));
                }
            }
            else
            {
                return(base.Problem("Failed conflict check."));
            }
        }