Ejemplo n.º 1
0
        public JsonResult Update(RestDto dto)
        {
            OperationResult oper;

            try
            {
                string strDay = ConfigurationHelper.GetAppSetting("RestDay");
                int    day    = int.Parse(strDay);
                Rest   rest   = _restContract.View(dto.Id);
                if (dto.PaidLeaveDays > day)
                {
                    oper = new OperationResult(OperationResultType.Error, "最多奖励" + strDay + "天");
                }
                double restDay = rest.PaidLeaveDays + dto.PaidLeaveDays;
                if (restDay > day)
                {
                    oper = new OperationResult(OperationResultType.Error, "超过最多奖励" + strDay + "天");
                }
                else
                {
                    rest.PaidLeaveDays = restDay;
                    rest.UpdatedTime   = DateTime.Now;
                    oper = _restContract.Update(rest);
                }
                return(Json(oper));
            }
            catch (Exception ex)
            {
                _Logger.Error <string>(ex.ToString());
                oper = new OperationResult(OperationResultType.Error, "服务器忙,请稍后重试");
                return(Json(oper));
            }
        }
Ejemplo n.º 2
0
        public bool Proccess(ProgramacaoTarefa programacaoTarefa)
        {
            var           log      = new Util.Log(ConfigurationManager.AppSettings["LogServico"]);
            RestDto <Log> response = null;

            try
            {
                _processBatch = new Repository.ApiClient.ProcessBatch(string.Empty, programacaoTarefa?.Tarefa.UrlAPI);
                response      = _processBatch.Process(programacaoTarefa).Result;
                if (response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    this.RenovaToken();
                    this.Proccess(programacaoTarefa);
                }
            }
            catch (Exception ex)
            {
                log.Escreve_Log($"URL Chamada: { programacaoTarefa.Tarefa.UrlAPI}");
                log.Escreve_Log(ex.Message);
                log.Escreve_Log(ex?.StackTrace);
                log.Escreve_Log(ex?.InnerException?.Message);
            }
            return(response.Success);
        }
Ejemplo n.º 3
0
        public JsonResult Create(RestDto dto)
        {
            var res = _restContract.Insert(dto);

            return(Json(res));
        }
Ejemplo n.º 4
0
        public JsonResult Create(string AdminIds, RestDto dto)
        {
            OperationResult oper;

            try
            {
                string strDay = ConfigurationHelper.GetAppSetting("RestDay");
                int    day    = int.Parse(strDay);
                //Rest rest = _restContract.Rests.Where(x => x.AdminId == dto.AdminId && x.IsEnabled == true && x.IsDeleted == false).FirstOrDefault();
                if (AdminIds == null || string.IsNullOrEmpty(AdminIds))
                {
                    return(Json(oper = new OperationResult(OperationResultType.Error, "请选择员工或部门")));
                }
                List <int>      adminIds    = AdminIds.Split(',').Select(a => int.Parse(a)).ToList();
                int             error       = 0;
                OperationResult oper_single = null;
                foreach (var id in adminIds)
                {
                    Administrator admin = _administratorContract.Administrators.FirstOrDefault(a => a.Id == id);
                    if (admin == null)
                    {
                        oper_single = new OperationResult(OperationResultType.Error, "该用户不存在");
                        error++;
                        continue;
                    }

                    Rest rest = _restContract.Rests.Where(x => x.AdminId == admin.Id && x.IsEnabled == true && x.IsDeleted == false).FirstOrDefault();
                    if (rest == null)
                    {
                        dto.AdminId  = admin.Id;
                        dto.RealName = admin.Member.RealName;
                        if (day < dto.PaidLeaveDays)
                        {
                            oper_single = new OperationResult(OperationResultType.Error, "最多奖励" + strDay + "天");
                            error++;
                            continue;
                        }
                        oper_single = _restContract.Insert(dto);
                    }
                    else
                    {
                        double restDay = rest.PaidLeaveDays + dto.PaidLeaveDays;
                        if (restDay > day)
                        {
                            oper_single = new OperationResult(OperationResultType.Error, "超过最多奖励" + strDay + "天");
                            error++;
                            continue;
                        }
                        rest.PaidLeaveDays = restDay;
                        rest.UpdatedTime   = DateTime.Now;
                        oper_single        = _restContract.Update(rest);
                    }
                    if (oper_single.ResultType == OperationResultType.Error)
                    {
                        error++;
                    }
                }
                if (error == 0)
                {
                    oper = new OperationResult(OperationResultType.Success, "添加成功");
                }
                else if (error == adminIds.Count())
                {
                    oper = new OperationResult(OperationResultType.Error, "添加失败");
                }
                else
                {
                    oper = new OperationResult(OperationResultType.Success, "添加成功" + (adminIds.Count() - error) + "条,失败" + error + "条");
                }
                return(Json(oper));
            }
            catch (Exception ex)
            {
                _Logger.Error <string>(ex.ToString());
                oper = new OperationResult(OperationResultType.Error, "服务器忙,请稍后重试");
                return(Json(oper));
            }
        }