public async Task <IActionResult> PostAsync([FromBody] UserModel model) { var tenantCode = await _workcontext.GetTenantCodeAsync(); //Nếu ko nhập pasword sẽ tự động random if (string.IsNullOrEmpty(model.Password)) { model.Password = RandomExtension.Random(10); } var idUser = await _identityService.CreateAsync(tenantCode, new CreateUserModel { Username = model.UserName, Password = model.Password, FullName = model.Infos.FullName, PhoneNumber = model.PhoneNumber, Email = model.Email, Metadata = model.Metadata }); var repoUser = _uow.GetRepository <IUserRepository>(); foreach (var idRole in model.IdRoles) { await repoUser.AssignRoleToUserAsync(idUser, idRole); } await _uow.CommitAsync(); //Tạo job send mail return(Ok()); }
public async Task <IActionResult> RegisterAsync([FromBody] RegisterModel model) { var tenantCode = await _workContext.GetTenantCodeAsync(); await _identityService.RegisterAsync(tenantCode, model); return(Ok()); }
public async Task <IActionResult> GetAsync([FromRoute] Guid code) { var idTenant = await _workContext.GetTenantCodeAsync(); var repo = _uow.GetRepository <IFileRepository>(); var file = await repo.GetByIdAsync(code); return(Ok(file)); }
public async Task <IActionResult> PostAsync([FromBody] RoleModel model) { var repoRole = _uow.GetRepository <IRoleRepository>(); //Create role var idRole = Guid.NewGuid(); await repoRole.InsertAsync(new Role { CreatedAt = DateTime.Now, CreatedAtUtc = DateTime.UtcNow, CreatedBy = _workContext.GetUserCode(), Id = idRole, TenantCode = await _workContext.GetTenantCodeAsync(), Name = model.Name, }); //Create claim var repoRoleClaim = _uow.GetRepository <IPermissionRepository>(); await repoRoleClaim.InsertRoleClaimsAsync(model.Claims.Select(x => new IdentityRoleClaim <Guid> { RoleId = idRole, ClaimType = x.Key, ClaimValue = x.Value }).ToList()); await _uow.CommitAsync(); return(Ok()); }
public async Task <IActionResult> GetAsync([FromQuery] Paging paging) { var idTenant = await _workContext.GetTenantCodeAsync(); var repoTenant = _uow.GetRepository <ITenantRepository>(); var paged = await repoTenant.PagingAsync(idTenant, paging); var tenantCodes = paged.Data.Select(x => x.Code).ToList(); var infos = (await repoTenant.GetInfoByCodesAsync(tenantCodes)).ToDictionary(x => x.Code, x => x); var hosts = (await repoTenant.GetHostByCodesAsync(tenantCodes)).GroupBy(x => x.Code).ToDictionary(x => x.Key, x => x.ToList()); var result = new Paged <TenantModel> { Page = paged.Page, Q = paged.Q, Size = paged.Size, TotalItems = paged.TotalItems, TotalPages = paged.TotalPages, }; var data = new List <TenantModel>(); foreach (var item in paged.Data) { var model = new TenantModel(); model.Code = item.Code; model.HostName = string.Join(';', hosts[item.Code].Select(x => x.HostName)); model.IsEnable = item.IsEnable; model.Theme = item.Theme; if (!infos.ContainsKey(item.Code)) { data.Add(model); continue; } var info = infos[item.Code]; model.Info = new TenantInfoModel { Id = info.Id, Code = info.Code, Address = info.Address, City = info.City, Country = info.Country, District = info.District, Emails = info.Emails, Fax = info.Fax, FullNameVi = info.FullNameVi, FullNameEn = info.FullNameEn, Phones = info.Phones, TaxCode = info.TaxCode }; data.Add(model); } result.Data = data; return(Ok(result)); }
public async Task <IActionResult> PostAsync([FromBody] OrganizationUnitModel model) { var context = await _workcontext.GetContextAsync(nameof(CorePolicy.OrganizationPolicy.OrganizationUnit_Create)); var repo = _uow.GetRepository <IOrganizationUnitRepository>(); await repo.InsertAsync(new OrganizationUnit { Description = model.Description, Code = Guid.NewGuid(), TenantCode = await _workcontext.GetTenantCodeAsync(), FullName = model.Name, CreatedAt = DateTime.Now, CreatedAtUtc = DateTime.UtcNow, CreatedBy = _workcontext.GetUserCode() }); await _uow.CommitAsync(); return(Ok()); }
public async Task <IActionResult> PostAsync([FromBody] LabelModel model) { var context = await _workcontext.GetContextAsync(nameof(CorePolicy.LabelPolicy.Label_Create)); var repo = _uow.GetRepository <ILabelRepository>(); await repo.InsertAsync(new Label { Color = model.Color, Description = model.Description, Icon = model.Icon, Code = Guid.NewGuid(), TenantCode = await _workcontext.GetTenantCodeAsync(), Name = model.Name, CreatedAt = DateTime.Now, CreatedAtUtc = DateTime.UtcNow, CreatedBy = _workcontext.GetUserCode() }); await _uow.CommitAsync(); return(Ok()); }
public async Task <IActionResult> GetAsync() { var tenantCode = await _workContext.GetTenantCodeAsync(); var repoTenant = _uow.GetRepository <ITenantRepository>(); var info = await repoTenant.GetInfoByCodeAsync(tenantCode); if (info == null) { return(NotFound()); } var model = new TenantInfoModel { Id = info.Id, Code = info.Code, FullNameVi = info.FullNameVi, TaxCode = info.TaxCode, Address = info.Address, City = info.City, District = info.District, Country = info.Country, Emails = info.Emails, Fax = info.Fax, FullNameEn = info.FullNameEn, LegalName = info.LegalName, BusinessType = info.BusinessType, }; //Nếu setting ko có metadata thì trả về kết quả luôn var repoSetting = _uow.GetRepository <ISettingRepository>(); var setting = await repoSetting.GetByKeyAsync(Guid.Empty, SettingKey.ThongTinDoanhNghiep_Khac.ToString()); if (setting == null) { return(Ok(model)); } //Metadata lấy được từ DB var metadatas = string.IsNullOrWhiteSpace(info.Metadata) ? new List <MetadataModel>() : JsonConvert.DeserializeObject <List <MetadataModel> >(info.Metadata); model.Metadata = new List <MetadataModel>(); var splited1 = setting.Value.Split("|"); foreach (var item in splited1) { var splited2 = item.Split(":"); var key = splited2[0]; var name = splited2[1]; var metadata = metadatas.FirstOrDefault(x => x.Key == key); //Nếu DB ko lưu value thì trả về null model.Metadata.Add(new MetadataModel { Key = key, Name = name, Value = metadata == null ? null : metadata.Value }); } return(Ok(model)); }
public async Task <IActionResult> GetAsync() { //lấy ra tất các các group default trong Db có tenantCode = Guid.Empty() hiển thị // setting nào có tenantCode != Guid.Empty rồi thì lấy dữ liệu db ra var tenantCode = await _workContext.GetTenantCodeAsync(); var repo = _uowCore.GetRepository <ISettingRepository>(); var settings = await repo.GetByTenantCodesAsync(new List <Guid> { Guid.Empty, tenantCode }); settings = settings.Where(x => !x.IsReadOnly).ToList(); //chỉ lấy setting nào đc hiển thị var defaulSettings = settings.Where(x => x.TenantCode == Guid.Empty); var entities = settings.Except(defaulSettings); var groupSettingKeys = _settingService.GetGroupSettings(); var settingGroups = new List <SettingGroupModel>(); var defaultGroups = defaulSettings.GroupBy(x => x.Group); //Hiển thị toàn bộ setting theo group foreach (var defaultGroup in defaultGroups) { //Nếu group nào chưa có DisplayName sẽ ko hiển thị ra ngoài if (!groupSettingKeys.ContainsKey(defaultGroup.Key)) { continue; } var settingGroup = new SettingGroupModel { Key = defaultGroup.Key, Name = groupSettingKeys[defaultGroup.Key], Settings = new List <SettingModel>() }; var defaultSettings = defaultGroup.ToList(); foreach (var defaultSetting in defaultSettings) { //Lấy cấu hình mặc định var setting = new SettingModel { Key = defaultSetting.Key, Name = defaultSetting.Name, Type = EnumExtension.ToEnum <SettingType>(defaultSetting.Type), Group = defaultSetting.Group, Options = string.IsNullOrWhiteSpace(defaultSetting.Options) ? new List <KeyValuePair <string, string> >() : defaultSetting.Options.Split("|").Select(x => x.Split(":")).Select(x => new KeyValuePair <string, string>(x[0], x[1])).ToList(), Value = defaultSetting.Value, Description = defaultSetting.Description }; //Lấy giá trị trên CSDL var entity = entities.FirstOrDefault(x => x.Key == defaultSetting.Key); if (entity != null) { setting.Id = entity.Id; setting.Code = entity.Code; setting.TenantCode = entity.TenantCode; setting.Value = entity.Value; } settingGroup.Settings.Add(setting); } settingGroups.Add(settingGroup); } return(Ok(settingGroups)); }