public override IHttpActionResult Post(Warehouse model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var featureWarehouseValue = _featureProvider.GetEditionFeatureValue(model.TenantId, StaticFeature.Warehouse.Name); bool isReachedMaximumWarehouseCount = _service.IsReachedMaximumWarehouseCount(model.TenantId, Convert.ToInt32(featureWarehouseValue)); if (isReachedMaximumWarehouseCount) { return(BadRequest("You already have added " + featureWarehouseValue + " warehouse. You can not add more warehouse with your current subscription.")); } var isWarehouseNameExist = _service.IsWarehouseNameExist(model.Name, model.Id, ActionType.Put); if (isWarehouseNameExist) { return(BadRequest(model.Name + " warehouse name already exist.")); } var isWarehouseCodeExist = _service.IsWarehouseCodeExist(model.Code, model.Id, ActionType.Put); if (isWarehouseCodeExist) { return(BadRequest(model.Name + " warehouse code already exist.")); } if (string.IsNullOrWhiteSpace(model.Id)) { model.Id = Guid.NewGuid().ToString(); } model.Active = true; _service.AddAsTenant(model); return(Ok(model.Id)); }
public async Task <IHttpActionResult> CreateUser(UserCreateRequestModel model) { if (string.IsNullOrWhiteSpace(model.Id)) { model.Id = Guid.NewGuid().ToString(); } model.UserName = model.Email; if (!string.IsNullOrWhiteSpace(model.UserName)) { ModelState.Remove("model.UserName"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (_service.IsEmailExist(model.Email)) { return(BadRequest($"{model.Email} email address already exist.")); } if (string.IsNullOrWhiteSpace(model.TenantId)) { model.TenantId = User.Identity.GetTenantId(); model.TenantName = User.Identity.GetTenantName(); model.CompanyId = User.Identity.GetCompanyId(); } else { var tenant = await _tenantProvider.GetTenantAsync(model.TenantId); var company = await _tenantProvider.GetTenantCompanyAsync(model.TenantId); model.TenantName = tenant.TenancyName; model.CompanyId = company?.Id; } model.CreatedBy = User.Identity.GetUserId(); model.IsActive = !model.SendActivationEmailToUser; model.EmailConfirmed = !model.SendActivationEmailToUser; var featureUsers = _featureProvider.GetEditionFeatureValue(model.TenantId, StaticFeature.Users.Name); bool isReachedMaximumUsersCount = _service.IsReachedMaximumUsersCount(model.TenantId, Convert.ToInt32(featureUsers)); if (isReachedMaximumUsersCount) { return(BadRequest("You already have added " + featureUsers + " users. You can not add more user with your current subscription.")); } var identityResult = await _service.CreateUserAsync(model); if (model.SendActivationEmailToUser) { var user = await _service.GetUserAsync(model.Id); user.EmailConfirmationCode = await UserManager.GenerateEmailConfirmationTokenAsync(model.Id); user.EmailConfirmed = false; user.EmailConfirmationCodeExpireTime = DateTime.Now.AddMinutes(30); user.PhoneConfirmationCode = await UserManager.GenerateChangePhoneNumberTokenAsync(model.Id, model.PhoneNumber); user.PhoneNumberConfirmed = false; user.PhoneConfirmationCodeExpireTime = DateTime.Now.AddMinutes(30); await _service.UpdateUserAsync(user); await _service.SendEmailConfirmationLinkAsync(model.Id, model.FullName(), model.Email, user.EmailConfirmationCode); } return(Ok(identityResult)); }
public override IHttpActionResult Post(Branch model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var company = _companyService.GetById(model.CompanyId); model.TenantId = company.TenantId; var featureBranchCount = _featureProvider.GetEditionFeatureValue(model.TenantId, StaticFeature.Showroom.Name); bool isReachedMaximumBranch = _service.IsReachedMaximumBranchCount(model.TenantId, Convert.ToInt32(featureBranchCount)); if (isReachedMaximumBranch) { return(BadRequest("You already have added " + featureBranchCount + " branch. You can not add more branch with your current subscription.")); } if (model.Type == BranchType.HeadOffice) { bool isHeadOfficeBranchExist = _service.IsHeadOfficeExist(model.Type, model.Id, model.TenantId); if (isHeadOfficeBranchExist) { return(BadRequest("Head office branch type already exist. You can not add duplicate head office.")); } } var isBranchExist = _service.IsBranchExist(model.Name, model.Id, model.TenantId); if (isBranchExist) { return(BadRequest(model.Name + " branch name already exist")); } if (string.IsNullOrWhiteSpace(model.LinkedWarehouseId)) { var warehouseId = Guid.NewGuid().ToString(); var warehouse = new Warehouse { Id = warehouseId, Code = model.Code, Name = model.Name, Address = model.Address, Created = model.Created, CreatedBy = model.CreatedBy, Modified = model.Modified, ModifiedBy = model.ModifiedBy, Active = true, Type = model.Type == BranchType.HeadOffice ? WarehouseType.HeadOffice : WarehouseType.Showroom, }; if (IsSystemAdminUser() && model.IsHostAction) { _warehouseService.CreateAsHost(warehouse); } else { _warehouseService.AddAsTenant(warehouse); } model.LinkedWarehouseId = warehouseId; } if (string.IsNullOrWhiteSpace(model.Id)) { model.Id = Guid.NewGuid().ToString(); } model.Active = true; if (IsSystemAdminUser() && model.IsHostAction) { Service.CreateAsHost(model); } else { Service.AddAsTenant(model); } return(Ok(model.Id)); }