Example #1
0
        public async Task <bool> UpdateAsync(UserEditModel model)
        {
            if (model == null)
            {
                return(ToResponse(false, Errors.invalid_data));
            }
            if (!_process.User.isAdmin)
            {
                if (!_process.User.Permissions.Contains("employee.me"))
                {
                    return(ToResponse(false, "Bạn không có quyền"));
                }
                if (model.Id != _process.User.Id)
                {
                    return(ToResponse(false, "Bạn không có quyền"));
                }
            }

            if (!string.IsNullOrWhiteSpace(model.Email) && !BusinessExtensions.IsValidEmail(model.Email.Trim(), 50))
            {
                return(ToResponse(false, "Email không hợp lệ"));
            }

            if (model.RoleId <= 0)
            {
                return(ToResponse(false, "Vui lòng chọn vai trò"));
            }

            if (string.IsNullOrWhiteSpace(model.UserName))
            {
                return(ToResponse(false, Errors.invalid_username_or_pass));
            }
            var user = await _rpEmployee.GetByUserNameAsync(model.UserName.Trim(), _process.User.Id);

            if (user == null)
            {
                return(ToResponse(false, "Tài khoản không tồn tại"));
            }
            user           = _mapper.Map <UserSql>(model);
            user.UpdatedBy = _process.User.Id;
            user.Email     = string.IsNullOrWhiteSpace(user.Email) ? string.Empty : user.Email.Trim().ToLower();

            var existUser = await _rpEmployee.GetByIdAsync(model.Id);

            if (!_process.User.isHead && model.RoleId == (int)RoleType.Head)
            {
                return(ToResponse(false, "Vai trò không hợp lệ"));
            }

            if (!_process.User.isAdmin && (model.RoleId == (int)RoleType.Admin || model.RoleId == (int)RoleType.Head))
            {
                return(ToResponse(false, "Vai trò không hợp lệ"));
            }

            if (_process.User.isRsmAsmSS || _process.User.isSale)
            {
                user.RoleId = existUser.RoleId;
            }
            return(ToResponse(await _rpEmployee.UpdateAsync(user)));
        }
Example #2
0
        protected override void OnStartup(StartupEventArgs e)
        {
            Helper.SetOnStartUpSettings();

            var dic = BusinessExtensions.GetExternalResources();

            if (dic != null)
            {
                Application.Current.Resources.MergedDictionaries.Add(dic);
            }

            base.OnStartup(e);
        }
Example #3
0
        public async Task <FileModel> UploadAsync(Stream stream, string key, string name, string webRootPath, string folder)
        {
            stream.Position = 0;
            string fileUrl = string.Empty;
            var    file    = BusinessExtensions.GetFileUploadUrl(name, webRootPath, folder, _process.User.Id);

            using (var fileStream = System.IO.File.Create(file.FullPath))
            {
                await stream.CopyToAsync(fileStream);

                fileStream.Close();
                return(file);
            }
        }
Example #4
0
        public async Task <object> UploadFileAsync(IFormFile file, int key, int fileId, string guildId, int profileId, int profileType, string rootPath)
        {
            if (file == null || string.IsNullOrWhiteSpace(guildId))
            {
                return(null);
            }
            var    _type     = string.Empty;
            string deleteURL = string.Empty;
            //string root = Server.MapPath($"~{Utility.FileUtils._profile_parent_folder}");

            var result = null as FileModel;

            try
            {
                if (!BusinessExtensions.IsNotValidFileSize(file.Length))
                {
                    using (Stream stream = new MemoryStream())
                    {
                        await file.CopyToAsync(stream);

                        result = await UploadAsync(stream, key.ToString(), file.FileName, rootPath, Utility.FileUtils.GenerateProfileFolder());
                    }
                }
                if (result != null)
                {
                    var id = await _rpFile.Add(new ProfileFileAddSql
                    {
                        FileKey       = key,
                        FileName      = result.Name,
                        FilePath      = result.FileUrl,
                        Folder        = result.Folder,
                        ProfileId     = profileId,
                        ProfileTypeId = profileType,
                        GuidId        = guildId,
                        FileId        = fileId
                    });

                    deleteURL = $"/media/delete/{id.data}/{guildId}";
                }

                return(CreateConfig(result, key, deleteURL));
            }
            catch (Exception e)
            {
                return(null);
            }
        }
        private bool ValidateCustomerDocument(CancelationModel cancelationModel)
        {
            if (cancelationModel.DocumentType == null &&
                BusinessExtensions.GetDocumentType(cancelationModel.CustomerDocument) == null)
            {
                return(false);
            }


            if (cancelationModel.CustomerDocument.RemoveDocumentSpecialCharacters().Length == 11 ||
                cancelationModel.CustomerDocument.RemoveDocumentSpecialCharacters().Length == 14)
            {
                return(true);
            }

            _logs.Add($"O cliente vinculado à apólice {cancelationModel.PolicyIdentifier} não possui um documento válido e foi ignorado no arquivo." +
                      $" NR_CNPJ_CPF [{cancelationModel.CustomerDocument}] - CD_TIPO_PESSO [{cancelationModel.DocumentType}]");
            return(false);
        }
Example #6
0
        public async Task <int> CreateAsync(UserCreateModel model)
        {
            if (model == null)
            {
                return(ToResponse(0, Errors.invalid_data));
            }
            if (string.IsNullOrWhiteSpace(model.UserName))
            {
                return(ToResponse(0, "Tên đăng nhập không được để trống"));
            }
            if (model.UserName.Contains(" "))
            {
                return(ToResponse(0, "Tên đăng nhập viết liền không dấu cách"));
            }
            if (string.IsNullOrWhiteSpace(model.Password))
            {
                return(ToResponse(0, "Mật khẩu không được để trống"));
            }
            if (model.Password.Trim().Length < 5)
            {
                return(ToResponse(0, "Mật khẩu phải có ít nhất 5 ký tự"));
            }
            if (string.IsNullOrWhiteSpace(model.PasswordConfirm))
            {
                return(ToResponse(0, "Mật khẩu xác thực không được để trống"));
            }
            if (model.Password != model.PasswordConfirm)
            {
                return(ToResponse(0, "Mật khẩu không khớp"));
            }

            if (model.RoleId <= 0)
            {
                return(ToResponse(0, "Vui lòng chọn vai trò"));
            }

            if (!string.IsNullOrWhiteSpace(model.Email) && !BusinessExtensions.IsValidEmail(model.Email.Trim(), 50))
            {
                return(ToResponse(0, "Email không hợp lệ"));
            }

            if (string.IsNullOrWhiteSpace(model.Code))
            {
                return(ToResponse(0, "Mã nhân viên không được để trống"));
            }

            var existUserName = await _rpEmployee.GetByUserNameAsync(model.UserName.Trim(), _process.User.Id);

            if (existUserName != null)
            {
                return(ToResponse(0, "Tên đăng nhập đã tồn tại"));
            }
            var existCode = await _rpEmployee.GetByCodeAsync(model.Code.Trim(), _process.User.Id);

            if (existCode != null)
            {
                return(ToResponse(0, "Mã đã tồn tại"));
            }

            var user = _mapper.Map <UserSql>(model);

            user.CreatedBy = _process.User.Id;
            user.Code      = user.Code.Trim().ToLower();
            user.Email     = user.Email.Trim().ToLower();
            user.UserName  = user.UserName.Trim().ToLower();
            user.Password  = user.Password.Trim();
            user.Password  = Utils.getMD5(model.Password);

            var response = await _rpEmployee.CreateAsync(user);

            return(ToResponse(response));
        }
        private List <string> CreateBodyLines(List <CancelationModel> population)
        {
            var bodyModel  = new FileBodyModel();
            var lineNumber = 1;

            foreach (var data in population)
            {
                if (data.PolicyInsurerIdentifier.isNullOrEmpty())
                {
                    _logs.Add($"A apólice {data.PolicyIdentifier} foi listada pra cancelamento, porém não pode ser cancelada, pois não possui um número de apólice");
                    continue;
                }

                var line = new LineFieldsModel()
                {
                    LineNumber = lineNumber++
                };
                foreach (var key in Configuration.BusinessSettings.DefaultValues.Keys)
                {
                    if (Configuration.BodyFields.ContainsKey(key))
                    {
                        var fieldConfiguration = Configuration.BodyFields[key];
                        var fileField          = new Field(ProcessType, fieldConfiguration)
                        {
                            Value = Configuration.BusinessSettings.DefaultValues[key]
                        };

                        line.Fields.Add(key, fileField);
                    }
                }


                CreateField(line, EnumFileFieldsType.Body, "TIPO_REGISTRO", Configuration.BusinessSettings.BodyIdentification);
                CreateField(line, EnumFileFieldsType.Body, "REGISTRO_SEQUENCIAL", line.LineNumber.ToString());
                CreateField(line, EnumFileFieldsType.Body, "DOCUMENTO", data.PolicyInsurerIdentifier.RemoveHdiDocumentFormat());
                CreateField(line, EnumFileFieldsType.Body, "ENDOSSO");
                CreateField(line, EnumFileFieldsType.Body, "NUMERO_CONTROLE_ITURAN", data.PolicyIdentifier.ToString());
                CreateField(line, EnumFileFieldsType.Body, "CODIGO_EQUIPAMENTO");
                CreateField(line, EnumFileFieldsType.Body, "DATA_CANCELAMENTO", $"{data.CancelationDate:yyyyMMdd}");
                CreateField(line, EnumFileFieldsType.Body, "DATA_PROCESSAMENTO");
                CreateField(line, EnumFileFieldsType.Body, "STATUS_CANCELAMENTO");
                CreateField(line, EnumFileFieldsType.Body, "CODIGO_OBSERVACAO");
                CreateField(line, EnumFileFieldsType.Body, "OBSERVACAO");
                CreateField(line, EnumFileFieldsType.Body, "VALOR_PREMIO");

                if (!ValidateCustomerDocument(data))
                {
                    continue;
                }

                CreateField(line, EnumFileFieldsType.Body, "TIPO_DOCUMENTO", data.DocumentType == null
                                                ? BusinessExtensions.GetDocumentType(data.CustomerDocument)?.ToInt().ToString()
                                                : data.DocumentType?.ToInt().ToString());

                CreateField(line, EnumFileFieldsType.Body, "NR_CNPJ_CPF", data.CustomerDocument.RemoveDocumentSpecialCharacters());

                bodyModel.Content.Add(line);
            }

            var bodyContent = new List <string>();

            foreach (var line in bodyModel.Content)
            {
                var body = new StringBuilder();
                foreach (var bodyField in line.PrepareSequenceFileFields())
                {
                    body.Append(bodyField.Value);
                }

                bodyContent.Add(body.Append(Environment.NewLine).ToString());
            }

            return(bodyContent);
        }
Example #8
0
        public async Task <object> UploadFileMcreditAsync(IFormFile file,
                                                          string rootPath,
                                                          int key,
                                                          int fileId,
                                                          string guildId,
                                                          int profileId,
                                                          string documentName,
                                                          string documentCode,
                                                          int documentId,
                                                          int groupId,
                                                          string mcId = null)
        {
            if (file == null || string.IsNullOrWhiteSpace(guildId))
            {
                return(null);
            }
            var    _type     = string.Empty;
            string deleteURL = string.Empty;
            var    result    = null as FileModel;

            try
            {
                if (!BusinessExtensions.IsNotValidFileSize(file.Length))
                {
                    using (Stream stream = new MemoryStream())
                    {
                        await file.CopyToAsync(stream);

                        result = await UploadAsync(stream, key.ToString(), file.FileName, rootPath, Utility.FileUtils.GenerateProfileFolderForMc());
                    }
                }
                if (result != null)
                {
                    var response = await _rpFile.AddMCredit(new MCProfileFileSqlModel
                    {
                        FileKey       = key,
                        FileName      = result.Name,
                        FilePath      = result.FileUrl,
                        Folder        = result.Folder,
                        ProfileId     = profileId,
                        ProfileTypeId = (int)ProfileType.MCredit,
                        GuidId        = guildId,
                        FileId        = fileId,
                        DocumentCode  = documentCode,
                        DocumentName  = documentName,
                        MC_DocumentId = documentId,
                        MC_GroupId    = groupId,
                        OrderId       = 0,
                        MC_MapBpmVar  = string.Empty,
                        McId          = mcId
                    });

                    deleteURL = $"/media/delete/{response.data}/{guildId}";
                }

                return(CreateConfig(result, key, deleteURL));
            }
            catch (Exception e)
            {
                return(null);
            }
        }