public async Task <IActionResult> CreateEnterpriseUnit([FromBody] EnterpriseUnitCreateM data) { var result = await _createService.CreateEnterpriseUnit(data, User.GetUserId()); if (result != null && result.ContainsKey(nameof(UserAccess.UnauthorizedAccess))) { return(Forbid()); } return(result == null ? (IActionResult)NoContent() : BadRequest(result)); }
/// <summary> /// Enterprise creation method /// </summary> /// <param name="data">Data</param> /// <param name="userId">User Id</param> /// <returns></returns> public async Task <Dictionary <string, string[]> > CreateEnterpriseUnit(EnterpriseUnitCreateM data, string userId) => await CreateUnitContext <EnterpriseUnit, EnterpriseUnitCreateM>(data, userId, unit => { var helper = new StatUnitCheckPermissionsHelper(_dbContext); helper.CheckRegionOrActivityContains(userId, data.Address?.RegionId, data.ActualAddress?.RegionId, data.PostalAddress?.RegionId, data.Activities.Select(x => x.ActivityCategoryId).ToList()); var legalUnits = _dbContext.LegalUnits.Where(x => data.LegalUnits.Contains(x.RegId)).ToList(); foreach (var legalUnit in legalUnits) { unit.LegalUnits.Add(legalUnit); } if (data.LegalUnits != null) { unit.HistoryLegalUnitIds = string.Join(",", data.LegalUnits); } return(Task.CompletedTask); });