public async Task <IActionResult> EditLegalUnit([FromBody] LegalUnitEditM data) { var result = await _editService.EditLegalUnit(data, User.GetUserId()); if (result != null && result.ContainsKey(nameof(UserAccess.UnauthorizedAccess))) { return(Forbid()); } return(result == null ? (IActionResult)NoContent() : BadRequest(result)); }
public async Task <Dictionary <string, string[]> > UpdateLog(int logId, string data, string userId) { var logEntry = await _dbContext.DataUploadingLogs .Include(l => l.DataSourceQueue) .ThenInclude(q => q.DataSource) .FirstOrDefaultAsync(l => l.Id == logId); if (logEntry == null) { throw new BadRequestException(nameof(Resource.UploadLogNotFound)); } var type = logEntry.DataSourceQueue.DataSource.StatUnitType; var definitionWithRegId = new { RegId = 0 }; var hasId = JsonConvert.DeserializeAnonymousType(data, definitionWithRegId).RegId > 0; Task <Dictionary <string, string[]> > task; switch (type) { case StatUnitTypes.LocalUnit: task = hasId ? _editSvc.EditLocalUnit(ParseModel <LocalUnitEditM>(), userId) : _createSvc.CreateLocalUnit(ParseModel <LocalUnitCreateM>(), userId); break; case StatUnitTypes.LegalUnit: task = hasId ? _editSvc.EditLegalUnit(ParseModel <LegalUnitEditM>(), userId) : _createSvc.CreateLegalUnit(ParseModel <LegalUnitCreateM>(), userId); break; case StatUnitTypes.EnterpriseUnit: task = hasId ? _editSvc.EditEnterpriseUnit(ParseModel <EnterpriseUnitEditM>(), userId) : _createSvc.CreateEnterpriseUnit(ParseModel <EnterpriseUnitCreateM>(), userId); break; default: throw new ArgumentOutOfRangeException( $"Parameter `{nameof(data)}`: value of type `{type.ToString()}` is not supported."); } var errors = await task; if (errors != null && errors.Any()) { return(errors); } logEntry.Status = DataUploadingLogStatuses.Done; await _dbContext.SaveChangesAsync(); return(null); T ParseModel <T>() where T : StatUnitModelBase { var result = JsonConvert.DeserializeObject <T>(data); result.DataSource = logEntry.DataSourceQueue.DataSource.Name; return(result); } }