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());
        }
        public async Task <IActionResult> OnPostApproveAsync()
        {
            string     storeId    = Request.Form["id-store"];
            WebAppUser webAppUser = await _userHandler.GetUserAsync(HttpContext.User);

            ApprovalHandler approvalHandler = new ApprovalHandler(_context, storeId);
            bool            isApprover      = await approvalHandler.IsApproverAsync(webAppUser);

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

            bool isOk = await approvalHandler.ActionApprove(webAppUser);

            if (isOk)
            {
                await SendEmailApprove(approvalHandler);
            }
            return(Ok());
        }
Beispiel #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());
        }