コード例 #1
0
        public async Task <List <Routine2NoticeOutput> > SendNoticeAsync(Routine2ChangeStepResult changeStepResult, bool realSend = true)
        {
            // تمپلیت‌های نامه را میگیریم
            var noticeTemplates = _context.Routine2Notice
                                  .AsNoTracking()
                                  .Where(q => q.RoutineId == changeStepResult.RoutineId)
                                  .Where(q => q.FromStep == changeStepResult.FromStep)
                                  .Where(q => q.ToStep == changeStepResult.ToStep)
                                  .ToList();

            var output = new List <Routine2NoticeOutput>();

            foreach (var noticeTemplate in noticeTemplates)
            {
                var noticeOutput = await this.SendNoticeAsync(noticeTemplate, changeStepResult.EntityId, realSend);

                output.Add(noticeOutput);
            }

            return(output);
        }
コード例 #2
0
        /// <summary>
        /// درصورتی از این توابع استفاده شود که جدول مورد نظر به صورت روتین باشد
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="RoutinId"></param>
        /// <param name="EntityId"></param>
        /// <param name="Action"></param>
        /// <param name="Description"></param>
        /// <returns></returns>
        public async Task <Routine2ChangeStepResult> ChangeStep(int userId, int RoutinId, int EntityId, Routine2Actions Action, string Description)
        {
            // گرفتن رکورد مورد نظر
            var entity = Entities.Find(EntityId);

            // زمان فعلی
            DateTime NowDateTime = DateTime.Now;


            // درصورتی که رکورد مورد نظر وجود نداشت باید خطا برگردانده شود
            if (entity == null)
            {
                throw new Exception($"داده‌ای با شناسه {EntityId} یافت نشد");
            }


            // مرحله بعدی فرآیند دراین قسمت به دست می‌آید
            var nextStep = await GetNextStep(1, RoutinId, Action);

            // درصورتی که مرحله بعدی -1 باشد باید خطا نمایش داده شود
            if (nextStep == -1)
            {
                throw new Exception("Something went wrong, next dashboard couldn't be -1");
            }


            // مرحله فعلی به دست آمده تا بتوان در ادامه با استفاده از آن تارخچه ثبت کنیم
            int fromStep    = Convert.ToInt32(entity.GetPropertyValue("RoutineStep"));
            int RoutineStep = fromStep;

            #region  ثبت لاگ جدید برای این کاربر که رکورد مورد را از یک مرحله به مرحله دیگر انتقال داده است

            CreateLog(new CreateRoutine2LogViewModel
            {
                RoutineId        = RoutinId,
                EntityId         = EntityId,
                Description      = Description,
                Action           = await GetActionTitle(RoutinId, fromStep, Action),
                Step             = fromStep,
                ToStep           = nextStep,
                UserId           = userId,
                CreatorUserId    = userId,
                RoutineRoleTitle = await GetRoutineRoleTitle(RoutinId, RoutineStep),
            });

            #endregion

            var routineVm = new EditRoutine2ViewModel(nextStep, Convert.ToDateTime(entity.GetPropertyValue("RoutineFlownDate").ToString()));

            // اگر در مرحله آخر باشیم، باید به روال برچست تمام شده بزنیم
            //if (entity.DoneSteps.Contains(nextStep))
            //    routineVm.RoutineIsDone = true;

            //// در صورتی که این آیتم مقدار درستی را اختیار کند، یعنی روتین به اتمام رسیده است
            //if (entity.SucceededSteps.Contains(nextStep))
            //    routineVm.RoutineIsSucceeded = true;

            entity.SetPropertyValue("RoutineStep", nextStep);
            entity.SetPropertyValue("RoutineFlownDate", NowDateTime);
            entity.SetPropertyValue("RoutineStepChangeDate", NowDateTime);

            await DbContext.SaveChangesAsync();

            var changeStepResult = new Routine2ChangeStepResult
            {
                Action      = Action,
                Description = Description,
                UserId      = userId,
                ToStep      = nextStep,
                FromStep    = fromStep,
                EntityId    = EntityId,
                RoutineId   = RoutinId,
            };

            //TODO
            //try { await _routine2Repository.SendNoticeAsync(changeStepResult); } catch (Exception) { }

            return(changeStepResult);
        }
コード例 #3
0
        public async Task <ServiceResult <Routine2ChangeStepResult> > ChangeStep(int RoutineId, int EntityId, Routine2Actions Action, string Description)
        {
            try
            {
                // گرفتن رکورد مورد نظر
                var entity = table.Find(EntityId);


                // درصورتی که رکورد مورد نظر وجود نداشت باید خطا برگردانده شود
                if (entity == null)
                {
                    throw new Exception($"داده‌ای با شناسه {EntityId} یافت نشد");
                }


                // مرحله بعدی فرآیند دراین قسمت به دست می‌آید
                var nextStep = GetNextStep(Action, entity, RoutineId);

                // درصورتی که مرحله بعدی -1 باشد باید خطا نمایش داده شود
                if (nextStep == -1)
                {
                    throw new Exception("Something went wrong, next dashboard couldn't be -1");
                }


                //=========================================================
                int userId   = _userResolverService.GetUserId();
                var fromStep = entity.RoutineStep;
                //=========================================================


                // ثبت لاگ جدید برای این کاربر که رکورد مورد را از یک مرحله به مرحله دیگر انتقال داده است
                _routine2Repository.CreateLog(new CreateRoutine2LogViewModel
                {
                    RoutineId        = RoutineId,
                    EntityId         = EntityId,
                    Description      = Description,
                    Action           = _routine2Repository.GetActionTitle(RoutineId, fromStep, Action),
                    Step             = fromStep,
                    ToStep           = nextStep,
                    UserId           = userId,
                    CreatorUserId    = userId,
                    RoutineRoleTitle = _routine2Repository.GetRoutineRoleTitle(RoutineId, entity.RoutineStep),
                });


                var routineVm = new EditRoutine2ViewModel(nextStep, entity.RoutineFlownDate);

                // اگر در مرحله آخر باشیم، باید به روال برچست تمام شده بزنیم
                if (entity.DoneSteps.Contains(nextStep))
                {
                    routineVm.RoutineIsDone = true;
                }

                // به صورت پیش‌فرض طرح رد شده است، مگر اینکه در مراحل تایید باشیم
                if (entity.SucceededSteps.Contains(nextStep))
                {
                    routineVm.RoutineIsSucceeded = true;
                }


                entity.RoutineStep           = nextStep;
                entity.RoutineFlownDate      = DateTime.Now;
                entity.RoutineStepChangeDate = DateTime.Now;

                _context.SaveChanges();

                var changeStepResult = new Routine2ChangeStepResult
                {
                    Action      = Action,
                    Description = Description,
                    UserId      = userId,
                    ToStep      = nextStep,
                    FromStep    = fromStep,
                    EntityId    = EntityId,
                    RoutineId   = RoutineId,
                };

                try { await _routine2Repository.SendNoticeAsync(changeStepResult); } catch (Exception) { }

                return(ServiceResult <Routine2ChangeStepResult> .Okay(changeStepResult));
            }
            catch (Exception ex)
            {
                return(ServiceResult <Routine2ChangeStepResult> .Exception(ex));
            }
        }
コード例 #4
0
        public async Task <ServiceResult <Routine2ChangeStepResult> > ChangeStep(int id, Routine2Actions action, string description, int userId)
        {
            try
            {
                var entity = _context.Test.FirstOrDefault(q => q.Id == id);
                if (entity == null)
                {
                    throw new Exception($"داده‌ای با شناسه {id} یافت نشد");
                }

                var nextStep = GetNextStep(id, action);
                if (nextStep == -1)
                {
                    throw new Exception("Something went wrong, next dashboard couldn't be -1");
                }


                var fromStep = entity.RoutineStep;

                _routine2Repository.CreateLog(new CreateRoutine2LogViewModel
                {
                    RoutineId        = TestRoutine.RoutineId,
                    EntityId         = id,
                    Description      = description,
                    Action           = _routine2Repository.GetActionTitle(TestRoutine.RoutineId, fromStep, action),
                    Step             = fromStep,
                    ToStep           = nextStep,
                    UserId           = userId,
                    CreatorUserId    = userId,
                    RoutineRoleTitle = _routine2Repository.GetRoutineRoleTitle(TestRoutine.RoutineId, entity.RoutineStep),
                });

                var routineVm = new EditRoutine2ViewModel(nextStep, entity.RoutineFlownDate);
                // اگر در مرحله آخر باشیم، باید به روال برچست تمام شده بزنیم
                if (TestRoutine.DoneSteps.Contains(nextStep))
                {
                    routineVm.RoutineIsDone = true;
                }

                // به صورت پیش‌فرض طرح رد شده است، مگر اینکه در مراحل تایید باشیم
                if (TestRoutine.SucceededSteps.Contains(nextStep))
                {
                    routineVm.RoutineIsSucceeded = true;
                }

                Mapper.Map(routineVm, entity);
                _context.SaveChanges();

                var changeStepResult = new Routine2ChangeStepResult
                {
                    Action      = action,
                    Description = description,
                    UserId      = userId,
                    ToStep      = nextStep,
                    FromStep    = fromStep,
                    EntityId    = entity.Id,
                    RoutineId   = TestRoutine.RoutineId,
                };

                //try { await _routine2Repository.SendNoticeAsync(changeStepResult); } catch (Exception ex) { }

                return(ServiceResult <Routine2ChangeStepResult> .Okay(changeStepResult));
            }
            catch (Exception ex)
            {
                return(ServiceResult <Routine2ChangeStepResult> .Exception(ex));
            }
        }