示例#1
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);
        }
示例#2
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);
        }