public async Task <ActionResult <ResponseModel> > Edit(PositionCreateViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            if (ConfigurationManager.AppSettings.IsTrialVersion)
            {
                response.SetIsTrial();
                return(Ok(response));
            }

            await using (_dbContext)
            {
                if (await _dbContext.UserPosition.
                    CountAsync(x => x.Name == model.Name && x.Code != model.Code) > 0)
                {
                    response.SetFailed("职位已存在");
                    return(Ok(response));
                }

                var entity = await _dbContext.UserPosition.FindAsync(model.Code);

                entity.SortID = model.SortID;
                entity.Name   = model.Name;
                entity.Status = model.Status;

                entity.ModifiedOn         = DateTime.Now;
                entity.ModifiedByUserGuid = AuthContextService.CurrentUser.Guid;
                entity.ModifiedByUserName = AuthContextService.CurrentUser.DisplayName;

                _dbContext.Entry(entity).State = EntityState.Modified;
                await _dbContext.SaveChangesAsync();

                return(Ok(response));
            }
        }
        public ActionResult <ResponseModel> Edit(FinanceInfoCreateViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            if (ConfigurationManager.AppSettings.IsTrialVersion)
            {
                response.SetIsTrial();
                return(Ok(response));
            }
            using (_dbContext)
            {
                //if (_dbContext.FinanceInfo.Count(x => x.Name == model.Name && x.Code != model.Code) > 0)
                //{
                //    response.SetFailed("财务管理已存在");
                //    return Ok(response);
                //}

                var entity = _mapper.Map <FinanceInfoCreateViewModel, FinanceInfo>(model);

                entity.ModifiedOn         = DateTime.Now;
                entity.ModifiedByUserGuid = AuthContextService.CurrentUser.Guid;
                entity.ModifiedByUserName = AuthContextService.CurrentUser.DisplayName;

                _dbContext.Entry(entity).State = EntityState.Modified;
                _dbContext.SaveChanges();
                return(Ok(response));
            }
        }
Exemple #3
0
        public async Task <ActionResult <ResponseModel> > Edit(ResumeCreateViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            if (ConfigurationManager.AppSettings.IsTrialVersion)
            {
                response.SetIsTrial();
                return(Ok(response));
            }

            await using (_dbContext)
            {
                if (await _dbContext.ResumeInfo.CountAsync(x => x.RealName == model.RealName &&
                                                           x.Code != model.Code) > 0)
                {
                    response.SetFailed("简历已存在");
                    return(Ok(response));
                }

                var entity = _mapper.Map <ResumeCreateViewModel, ResumeInfo>(model);



                entity.ModifiedOn         = DateTime.Now;
                entity.ModifiedByUserGuid = AuthContextService.CurrentUser.Guid;
                entity.ModifiedByUserName = AuthContextService.CurrentUser.DisplayName;

                _dbContext.Entry(entity).State = EntityState.Modified;
                await _dbContext.SaveChangesAsync();

                return(Ok(response));
            }
        }
Exemple #4
0
        public async Task <ActionResult <TemplateEditRetModel> > Edit(TemplateEditViewModel model)
        {
            await using (_dbContext)
            {
                var entity = await _dbContext.WorkflowTemplate.FindAsync(model.Code);

                entity.Name        = model.Name;
                entity.Description = model.Description;
                entity.ParentCode  = model.ParentCode;
                entity.Visible     = model.Visible;
                entity.IsStepFree  = model.IsStepFree;

                entity.ModifiedByUserGuid = AuthContextService.CurrentUser.Guid;
                entity.ModifiedByUserName = AuthContextService.CurrentUser.DisplayName;
                entity.ModifiedOn         = DateTime.Now;
                if (!ConfigurationManager.AppSettings.IsTrialVersion)
                {
                    entity.Status = model.Status;
                }
                _dbContext.Entry(entity).State = EntityState.Modified;
                await _dbContext.SaveChangesAsync();

                var response = ResponseModelFactory.CreateInstance;
                response.SetSuccess();
                return(Ok(response));
            }
        }
Exemple #5
0
        public async Task <ActionResult <ResponseModel> > Edit(DictionaryCreateViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            if (ConfigurationManager.AppSettings.IsTrialVersion)
            {
                response.SetIsTrial();
                return(Ok(response));
            }

            await using (_dbContext)
            {
                if (await _dbContext.SystemDictionary.CountAsync(x => x.Name == model.Name &&
                                                                 x.Code != model.Code) > 0)
                {
                    response.SetFailed("字典已存在");
                    return(Ok(response));
                }

                var entity = _mapper.Map <DictionaryCreateViewModel, SystemDictionary>(model);
                _dbContext.Entry(entity).State = EntityState.Modified;
                await _dbContext.SaveChangesAsync();

                //更新缓存
                _dictionaryService.ClearDictionaryCache();
                return(Ok(response));
            }
        }
Exemple #6
0
        public async Task <ActionResult <ResponseModel> > Edit(StepCreateViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            if (ConfigurationManager.AppSettings.IsTrialVersion)
            {
                response.SetIsTrial();
                return(Ok(response));
            }

            await using (_dbContext)
            {
                if (await _dbContext.WorkflowStep.
                    CountAsync(x => x.Title == model.Title && x.Code != model.Code) > 0)
                {
                    response.SetFailed("步骤已存在");
                    return(Ok(response));
                }

                var entity = await _dbContext.WorkflowStep.FindAsync(model.Code);

                entity.Title         = model.Title;
                entity.SortID        = model.SortID;
                entity.TemplateCode  = model.TemplateCode;
                entity.UserList      = string.Join('|', model.UserList);
                entity.Status        = model.Status;
                entity.IsCounterSign = model.IsCounterSign;


                entity.ModifiedOn         = DateTime.Now;
                entity.ModifiedByUserGuid = AuthContextService.CurrentUser.Guid;
                entity.ModifiedByUserName = AuthContextService.CurrentUser.DisplayName;

                _dbContext.Entry(entity).State = EntityState.Modified;
                await _dbContext.SaveChangesAsync();

                return(Ok(response));
            }
        }
Exemple #7
0
        public async Task <ActionResult <ResponseModel> > Edit(ReceiverCreateViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            if (ConfigurationManager.AppSettings.IsTrialVersion)
            {
                response.SetIsTrial();
                return(Ok(response));
            }

            await using (_dbContext)
            {
                if (model.IsCheck)
                {
                    response.SetFailed("改审批已完成");
                    return(Ok(response));
                }
                if (!model.IsCheck && model.Status == -1)
                {
                    response.SetFailed("改审批已过期");
                    return(Ok(response));
                }
                if (await _dbContext.WorkflowReceiver.
                    AnyAsync(a => a.Status == "2" && a.WorkflowCode == model.WorkflowCode))
                {
                    response.SetFailed("该审批已拒绝");
                    return(Ok(response));
                }


                // var entity = _mapper.Map<ReceiverCreateViewModel, WorkflowReceiver>(model);
                var entity = await _dbContext.WorkflowReceiver.FindAsync(model.Id);

                //进行下一步审批
                var canNext = (await _dbContext.WorkflowReceiver.
                               CountAsync(r => r.WorkflowCode == entity.WorkflowCode && r.StepCode == entity.StepCode &&
                                          !r.IsCheck)) == 1;
                if (!string.IsNullOrEmpty(model.NextStepCode) &&
                    !string.IsNullOrEmpty(model.Approver) && model.Status == 1 && canNext)
                {
                    //var step = await _dbContext.WorkflowStep.FindAsync(model.NextStepCode);
                    //var nextStepCode = "";
                    //if (step != null)
                    //{
                    //    //var steps = await _dbContext.WorkflowStep.
                    //    //    Where(s => s.TemplateCode == step.TemplateCode).OrderBy(o=>o.SortID).ToListAsync();
                    //    //if (steps.Count > int.Parse(step.SortID))
                    //    //{
                    //    //    nextStepCode = steps[int.Parse(step.SortID)]?.Code;
                    //    //}
                    //    nextStepCode= (await _dbContext.WorkflowStep.
                    //   Where(s => s.TemplateCode == step.TemplateCode&&string.Compare(s.SortID,step.SortID)>0).OrderBy(o=>o.SortID)
                    //   .FirstOrDefaultAsync()).Code;
                    //}
                    var receivers = new List <WorkflowReceiver>();
                    foreach (var user in model.Approver.Split(','))
                    {
                        var u = Guid.Parse(user);
                        //发送审批到下一个人
                        var receiver = WorkflowReceiverFactory.CreateInstance;
                        receiver.Type         = entity.Type;
                        receiver.User         = u;
                        receiver.Description  = entity.Description;
                        receiver.WorkflowCode = entity.WorkflowCode;
                        receiver.CreateUser   = AuthContextService.CurrentUser.Guid;
                        receiver.StepCode     = model.NextStepCode;
                        receiver.TemplateCode = entity.TemplateCode;
                        receivers.Add(receiver);
                        //发送纸飞机通知
                        var toDoUser = await _dbContext.DncUser.FindAsync(entity.User);

                        var rUser = await _dbContext.DncUser.FindAsync(u);

                        var workflowList = await _dbContext.WorkflowList.FindAsync(receiver.WorkflowCode);

                        await _telegramService.SendTextMessageAsync(rUser.TelegramChatId,
                                                                    $"请审核用户【{toDoUser.DisplayName}】{workflowList.Title}", rUser.TelegramBotToken);
                    }

                    //如果审批状态为未通过需更新工作状态
                    if (model.Status == 2)
                    {
                        var work = await _dbContext.WorkflowList.
                                   FindAsync(model.WorkflowCode);

                        work.Status = "2";
                        _dbContext.Entry(work).State = EntityState.Modified;
                    }
                    //全部同意也需要更新工作转态
                    if (model.Status == 1)
                    {
                        var disagree = await _dbContext.WorkflowReceiver
                                       .Where(r => r.WorkflowCode == model.WorkflowCode)
                                       .CountAsync();

                        var step = await _dbContext.WorkflowStep.Where(s => s.TemplateCode == model.TemplateCode)
                                   .OrderBy(m => m.SortID).LastOrDefaultAsync();

                        if (step.Code == model.StepCode && disagree == 1)
                        {
                            var work = await _dbContext.WorkflowList.
                                       FindAsync(model.WorkflowCode);

                            work.Status = "1";
                            _dbContext.Entry(work).State = EntityState.Modified;
                        }
                    }


                    await _dbContext.WorkflowReceiver.AddRangeAsync(receivers);
                }



                //设置审批状态
                entity.Status      = model.Status.ToString();
                entity.Description = model.Description;
                entity.Note        = model.Note;
                //设置已审批
                entity.IsCheck   = true;
                entity.CheckDate = DateTime.Now;
                _dbContext.Entry(entity).State = EntityState.Modified;
                await _dbContext.SaveChangesAsync();

                return(Ok(response));
            }
        }
Exemple #8
0
        public async Task <ActionResult <ResponseModel> > Edit(WorkflowListCreateViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            if (ConfigurationManager.AppSettings.IsTrialVersion)
            {
                response.SetIsTrial();
                return(Ok(response));
            }

            await using (_dbContext)
            {
                if (model.Status != "0")
                {
                    response.SetFailed("改工作不在【新工作】不能修改");
                    return(Ok(response));
                }

                var entity = _mapper.Map <WorkflowListCreateViewModel, WorkflowList>(model);
                //进行下一步审批
                if (!string.IsNullOrEmpty(model.NextStepCode) && !string.IsNullOrEmpty(model.Approver))
                {
                    //进行中
                    entity.Status = "1";
                    //进行中
                    entity.Status          = "1";
                    entity.CurrentStepCode = model.NextStepCode;
                    var step = await _dbContext.WorkflowStep.FindAsync(model.NextStepCode);

                    if (step != null)
                    {
                        var steps = await _dbContext.WorkflowStep.
                                    Where(s => s.TemplateCode == step.TemplateCode).OrderBy(o => o.SortID).ToListAsync();

                        if (steps.Count > int.Parse(step.SortID))
                        {
                            entity.NextStepCode = steps[int.Parse(step.SortID)]?.Code;
                        }
                    }
                    var receivers = new List <WorkflowReceiver>();
                    foreach (var user in model.Approver.Split(','))
                    {
                        var u = Guid.Parse(user);
                        //发送审批到下一个人
                        var receiver = WorkflowReceiverFactory.CreateInstance;
                        receiver.Type         = entity.Type;
                        receiver.User         = u;
                        receiver.Description  = entity.Description;
                        receiver.WorkflowCode = entity.Code;
                        receiver.CreateUser   = entity.User;
                        receiver.StepCode     = entity.CurrentStepCode;
                        receiver.TemplateCode = step?.TemplateCode;
                        receivers.Add(receiver);
                        //发送纸飞机通知
                        var toDoUser = await _dbContext.DncUser.FindAsync(entity.User);

                        var rUser = await _dbContext.DncUser.FindAsync(u);

                        await _telegramService.SendTextMessageAsync(rUser.TelegramChatId,
                                                                    $"请审核用户【{toDoUser.DisplayName}】{entity.Title}", rUser.TelegramBotToken);
                    }

                    await _dbContext.WorkflowReceiver.AddRangeAsync(receivers);
                }
                _dbContext.Entry(entity).State = EntityState.Modified;
                await _dbContext.SaveChangesAsync();

                return(Ok(response));
            }
        }
        public async Task <ActionResult <ResponseModel> > Edit(DepartmentCreateViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            if (ConfigurationManager.AppSettings.IsTrialVersion)
            {
                response.SetIsTrial();
                return(Ok(response));
            }

            await using (_dbContext)
            {
                if (_dbContext.UserDepartment.Count(x => x.Name == model.Name && x.Code != model.Code) > 0)
                {
                    response.SetFailed("部门已存在");
                    return(Ok(response));
                }

                var entity = await _dbContext.UserDepartment.FindAsync(model.Code);

                entity.Monday    = model.WorkTime;
                entity.Wednesday = model.WorkTime;
                entity.Thursday  = model.WorkTime;
                entity.Tuesday   = model.WorkTime;
                entity.Friday    = model.WorkTime;
                entity.Saturday  = model.WorkTime;
                entity.Sunday    = model.WorkTime;
                entity.SortID    = model.SortID;
                entity.Phone1    = model.Phone1;
                entity.Email     = model.Email;
                entity.Name      = model.Name;
                entity.Status    = model.Status;

                entity.ModifiedOn         = DateTime.Now;
                entity.ModifiedByUserGuid = AuthContextService.CurrentUser.Guid;
                entity.ModifiedByUserName = AuthContextService.CurrentUser.DisplayName;
                foreach (var day in model.RestDays)
                {
                    switch (int.Parse(day))
                    {
                    case 1:
                        entity.Monday = null;
                        break;

                    case 2:
                        entity.Tuesday = null;
                        break;

                    case 3:
                        entity.Wednesday = null;
                        break;

                    case 4:
                        entity.Thursday = null;
                        break;

                    case 5:
                        entity.Friday = null;
                        break;

                    case 6:
                        entity.Saturday = null;
                        break;

                    case 7:
                        entity.Sunday = null;
                        break;

                    default:
                        break;
                    }
                }
                _dbContext.Entry(entity).State = EntityState.Modified;
                await _dbContext.SaveChangesAsync();

                return(Ok(response));
            }
        }