Exemplo n.º 1
0
        public async Task <IActionResult> OnPostRejectAsync()
        {
            string storeId    = Request.Form["id-store"];
            bool   completeOk = bool.TryParse(Request.Form["checkbox-complete"], out bool completeCheck);
            bool   stageOk    = int.TryParse(Request.Form["next-stage"], out int stageId);

            if (!stageOk || !completeOk)
            {
                return(NotFound());
            }

            WebAppUser webAppUser = await _userHandler.GetUserAsync(HttpContext.User);

            ApprovalHandler approvalHandler = new ApprovalHandler(_context, storeId);

            bool isFirstStage = await approvalHandler.IsFirstStageAsync();

            bool isApprover = await approvalHandler.IsApproverAsync(webAppUser);

            if (!isApprover || isFirstStage)
            {
                return(NotFound());
            }

            bool isOk = await approvalHandler.ActionReject(completeCheck, stageId, webAppUser);

            if (isOk)
            {
                await SendEmailReject(approvalHandler);
            }
            return(Ok());
        }
Exemplo n.º 2
0
        private async Task <bool> SendEmailApprove(ApprovalHandler approvalHandler)
        {
            string ownerId = await approvalHandler.GetOwnerID();

            WebAppUser userCurrent = await _userHandler.GetUserAsync(HttpContext.User);

            WebAppUser userOwner = _userHandler.Users.Where(x => x.Id == ownerId).FirstOrDefault();
            string     storeId   = await approvalHandler.GetStoreID();

            MtdForm mtdForm = await approvalHandler.GetFormAsync();

            MtdApprovalStage stageNext = await approvalHandler.GetNextStageAsync();

            if (stageNext != null)
            {
                WebAppUser userNext   = _userHandler.Users.Where(x => x.Id == stageNext.UserId).FirstOrDefault();
                BlankEmail blankEmail = new BlankEmail
                {
                    Subject = _localizer["Approval event"],
                    Email   = userNext.Email,
                    Header  = _localizer["Approval required"],
                    Content = new List <string> {
                        $"<strong>{_localizer["Document"]} - {mtdForm.Name}</strong>",
                        $"{_localizer["User"]} {userCurrent.Title} {_localizer["approved the document at"]} {DateTime.Now}",
                        $"{_localizer["Click on the link to view the document that required to approve."]}",
                        $"<a href='http://{HttpContext.Request.Host}/workplace/store/details?id={storeId}'>{_localizer["Document link"]}</a>"
                    }
                };

                await _emailSender.SendEmailBlankAsync(blankEmail);
            }

            bool IsFirstStage = await approvalHandler.IsFirstStageAsync();

            if (!IsFirstStage)
            {
                BlankEmail blankEmail = new BlankEmail
                {
                    Subject = _localizer["Approval event"],
                    Email   = userOwner.Email,
                    Header  = _localizer["Approval process event"],
                    Content = new List <string> {
                        $"<strong>{_localizer["Document"]} - {mtdForm.Name}</strong>",
                        $"{_localizer["User"]} {userCurrent.Title} {_localizer["approved the document at"]} {DateTime.Now}",
                        $"{_localizer["Click on the link to view the document."]}",
                        $"<a href='http://{HttpContext.Request.Host}/workplace/store/details?id={storeId}'>{_localizer["Document link"]}</a>"
                    }
                };
                await _emailSender.SendEmailBlankAsync(blankEmail);
            }

            return(true);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> OnGetAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            MtdStore = await _context.MtdStore.FirstOrDefaultAsync(m => m.Id == id);

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

            var user = await _userHandler.GetUserAsync(HttpContext.User);

            bool isViewer = await _userHandler.IsViewer(user, MtdStore.MtdForm, MtdStore.Id);

            IsEditor = await _userHandler.IsEditor(user, MtdStore.MtdForm, MtdStore.Id);

            IsInstallerOwner = await _userHandler.IsInstallerOwner(user, MtdStore.MtdForm, MtdStore.Id);

            if (!isViewer)
            {
                return(Forbid());
            }


            MtdForm = await _context.MtdForm.Include(m => m.InverseParentNavigation).FirstOrDefaultAsync(x => x.Id == MtdStore.MtdForm);

            MtdLogDocument edited = await _context.MtdLogDocument.Where(x => x.MtdStore == MtdStore.Id).OrderByDescending(x => x.TimeCh).FirstOrDefaultAsync();

            MtdLogDocument created = await _context.MtdLogDocument.Where(x => x.MtdStore == MtdStore.Id).OrderBy(x => x.TimeCh).FirstOrDefaultAsync();

            StoreOwner = await _context.MtdStoreOwner.Where(x => x.Id == MtdStore.Id).FirstOrDefaultAsync();

            ChangesHistory = new ChangesHistory
            {
                CreateByTime = MtdStore.Timecr.ToString()
            };

            if (edited != null)
            {
                ChangesHistory.LastEditedUser = edited.UserName;
                ChangesHistory.LastEditedTime = edited.TimeCh.ToString();
            }

            if (created != null)
            {
                if (MtdStore.Timecr.Date == created.TimeCh.Date)
                {
                    ChangesHistory.CreateByUser = created.UserName;
                }
            }

            List <WebAppUser> webAppUsers = await _userHandler.GetUsersInGroupsAsync(user);

            ViewData["UsersList"] = new SelectList(webAppUsers, "Id", "Title");

            ApprovalHandler approvalHandler = new ApprovalHandler(_context, MtdStore.Id);

            IsApprover = await approvalHandler.IsApproverAsync(user);

            IsFirstStage = await approvalHandler.IsFirstStageAsync();

            IList <MtdApprovalStage> stages = await approvalHandler.GetStagesDownAsync();

            ViewData["Stages"] = new SelectList(stages.OrderByDescending(x => x.Stage), "Id", "Name");

            List <string> partIds = await approvalHandler.GetWilBeBlockedPartsIds();

            BlockParts = new List <MtdFormPart>();
            if (partIds.Count > 0)
            {
                BlockParts = await _context.MtdFormPart.Where(x => partIds.Contains(x.Id)).OrderBy(x => x.Sequence).ToListAsync();
            }
            IsFormApproval = await approvalHandler.IsApprovalFormAsync();

            if (IsFormApproval)
            {
                ApprovalStatus = await approvalHandler.GetStatusAsync(user);
            }


            return(Page());
        }