示例#1
0
        public static async Task <List <ApprovalStore> > GetStoreStatusAsync(OrderMakerContext context, IList <string> storeIds, WebAppUser appUser)
        {
            List <ApprovalStore> result = new List <ApprovalStore>();

            IList <MtdStoreApproval> mtdStoreApprovals = await context.MtdStoreApproval
                                                         .Include(x => x.MdApproveStageNavigation)
                                                         .Where(x => storeIds.Contains(x.Id))
                                                         .ToListAsync();

            List <string>            approvalIds = mtdStoreApprovals.Select(x => x.MdApproveStageNavigation.MtdApproval).ToList();
            IList <MtdApprovalStage> stages      = await context.MtdApprovalStage
                                                   .Where(x => approvalIds.Contains(x.MtdApproval))
                                                   .OrderBy(x => x.Stage).ToListAsync();

            foreach (string storeId in storeIds)
            {
                ApprovalStore approvalStore = new ApprovalStore
                {
                    StoreId = storeId
                };
                MtdStoreApproval sa = mtdStoreApprovals.Where(x => x.Id == storeId).FirstOrDefault();
                if (sa == null)
                {
                    approvalStore.Status = ApprovalStatus.Start;
                }
                else
                {
                    bool   isComplete = sa.Complete == 1 ? true : false;
                    int    approved   = sa.Result;
                    string approvalId = sa.MdApproveStageNavigation.MtdApproval;
                    int    currentId  = sa.MtdApproveStage;

                    int firstId = stages.Where(x => x.MtdApproval == approvalId)
                                  .OrderBy(x => x.Stage).Select(x => x.Id).FirstOrDefault();

                    bool isFirst    = currentId == firstId ? true : false;
                    bool isApprover = sa.MdApproveStageNavigation.UserId == appUser.Id ? true : false;
                    approvalStore.Status = DefineStatus(isComplete, approved, isFirst, isApprover);
                }

                result.Add(approvalStore);
            }

            return(result);
        }
示例#2
0
        public async Task <bool> ActionReject(bool complete, int idStage, WebAppUser webAppUser)
        {
            MtdStore mtdStore = await GetStoreAsync();

            if (mtdStore.MtdStoreApproval != null && mtdStore.MtdStoreApproval.Complete == 1)
            {
                return(false);
            }

            MtdApproval mtdApproval = await GetApproval();

            MtdApprovalStage currentStage = await GetCurrentStageAsync();

            MtdApprovalStage prevStage;

            if (!complete)
            {
                prevStage = mtdApproval.MtdApprovalStage.Where(x => x.Id == idStage).FirstOrDefault();
            }
            else
            {
                prevStage = await GetCurrentStageAsync();
            }

            if (prevStage == null)
            {
                return(false);
            }

            var allStages = await GetStagesAsync();

            var blockPartsStage = allStages.Where(x => x.Stage < prevStage.Stage).FirstOrDefault();

            MtdStoreApproval storeApproval = new MtdStoreApproval
            {
                Id = mtdStore.Id,
                MtdApproveStage = prevStage.Id,
                PartsApproved   = blockPartsStage == null ? "&" : blockPartsStage.BlockParts,
                Complete        = complete ? (sbyte)1 : (sbyte)0,
                Result          = -1,
            };

            if (mtdStore.MtdStoreApproval == null)
            {
                await _context.MtdStoreApproval.AddAsync(storeApproval);
            }
            else
            {
                try
                {
                    _context.MtdStoreApproval.Update(storeApproval);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }

            MtdLogApproval mtdLogApproval = new MtdLogApproval()
            {
                MtdStore = mtdStore.Id,
                Result   = -1,
                Stage    = currentStage.Stage,
                Timecr   = DateTime.Now,
                UserId   = webAppUser.Id
            };

            await _context.MtdLogApproval.AddAsync(mtdLogApproval);



            try
            {
                await _context.SaveChangesAsync();
            }
            catch
            {
                return(false);
            }

            return(true);
        }
示例#3
0
        public async Task <bool> ActionApprove(WebAppUser webAppUser)
        {
            MtdStore mtdStore = await GetStoreAsync();

            if (mtdStore.MtdStoreApproval != null && mtdStore.MtdStoreApproval.Complete == 1)
            {
                return(false);
            }

            MtdApprovalStage currentStage = await GetCurrentStageAsync();

            MtdApprovalStage nextStage = await GetNextStageAsync();

            sbyte complete = 0;

            if (nextStage == null)
            {
                complete = 1; nextStage = await GetLastStageAsync();
            }
            ;

            MtdStoreApproval storeApproval = new MtdStoreApproval
            {
                Id = mtdStore.Id,
                MtdApproveStage = nextStage.Id,
                PartsApproved   = currentStage.BlockParts,
                Complete        = complete,
                Result          = 1,
            };

            if (mtdStore.MtdStoreApproval == null)
            {
                await _context.MtdStoreApproval.AddAsync(storeApproval);
            }
            else
            {
                _context.MtdStoreApproval.Update(storeApproval);
            }

            MtdLogApproval mtdLogApproval = new MtdLogApproval()
            {
                MtdStore = mtdStore.Id,
                Result   = 1,
                Stage    = currentStage.Id,
                Timecr   = DateTime.Now,
                UserId   = webAppUser.Id
            };

            await _context.MtdLogApproval.AddAsync(mtdLogApproval);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }

            return(true);
        }