Beispiel #1
0
        public IActionResult New()
        {
            var model = new NewLinksView();

            model.DepartmentId = DepartmentId;

            return(View(model));
        }
Beispiel #2
0
        public IActionResult Enable(int linkId)
        {
            var link = _departmentLinksService.GetLinkById(linkId);

            if (link.LinkedDepartmentId != DepartmentId)
            {
                Unauthorized();
            }

            var model = new NewLinksView();

            model.DepartmentId = DepartmentId;
            model.Link         = link;

            return(View(model));
        }
Beispiel #3
0
        public IActionResult Enable(NewLinksView model)
        {
            var link = _departmentLinksService.GetLinkById(model.Link.DepartmentLinkId);

            if (link.LinkedDepartmentId != DepartmentId)
            {
                Unauthorized();
            }

            link.DepartmentColor = model.Link.DepartmentColor;
            link.LinkEnabled     = true;
            link.LinkAccepted    = DateTime.UtcNow;

            _departmentLinksService.Save(link);

            return(RedirectToAction("Index"));
        }
Beispiel #4
0
        public async Task <IActionResult> Enable(NewLinksView model, CancellationToken cancellationToken)
        {
            var link = await _departmentLinksService.GetLinkByIdAsync(model.Link.DepartmentLinkId);

            if (link.LinkedDepartmentId != DepartmentId)
            {
                Unauthorized();
            }

            link.DepartmentColor = model.Link.DepartmentColor;
            link.LinkEnabled     = true;
            link.LinkAccepted    = DateTime.UtcNow;

            await _departmentLinksService.SaveAsync(link, cancellationToken);

            return(RedirectToAction("Index"));
        }
Beispiel #5
0
        public async Task <IActionResult> New(NewLinksView model, CancellationToken cancellationToken)
        {
            if (!await _limitsService.CanDepartmentUseLinksAsync(DepartmentId))
            {
                model.Message = $"Unable to a created a link while on the Free Plan.";
                return(View(model));
            }

            var linkedDepartment = await _departmentLinksService.GetDepartmentByLinkCodeAsync(model.LinkCode);

            if (linkedDepartment == null)
            {
                model.Message = $"Unable to find a department with a link code of {model.LinkCode}, please check the code and try again.";
                return(View(model));
            }

            if (linkedDepartment.DepartmentId == DepartmentId)
            {
                model.Message = $"Unable to a link to your own department.";
                return(View(model));
            }

            if (!await _limitsService.CanDepartmentUseLinksAsync(linkedDepartment.DepartmentId))
            {
                model.Message = $"Unable to a link to a department on the Free Plan.";
                return(View(model));
            }

            model.Link.DepartmentId       = DepartmentId;
            model.Link.LinkedDepartmentId = linkedDepartment.DepartmentId;
            model.Link.LinkEnabled        = false;
            model.Link.LinkCreated        = DateTime.UtcNow;

            await _departmentLinksService.SaveAsync(model.Link, cancellationToken);

            await _emailService.SendNewDepartmentLinkMailAsync(model.Link);

            return(RedirectToAction("Index"));
        }