public async Task <ActionResult> Post([FromBody] Art_OrganizCreationDTO art_OrganizCreation) { var organizacijas = _mapper.Map <Art_Organiz>(art_OrganizCreation); Art_Organiz id = _context.Art_Organiz_.Find(art_OrganizCreation.ID); // iegūstu, vai eksistē ID if (id != null) // ja tāds ID eksistē, tad Error/Conflict { Console.WriteLine("id aizņemts: " + id.ID); // Statusa kodi ASP.NET.Core - https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.statuscodes?view=aspnetcore-3.1 // https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.controllerbase.conflict?view=aspnetcore-3.1 ErrorID error = new ErrorID("Šāds ID jau eksistē", "409"); return(Conflict(error.ErrorText()));; } else { _context.Add(organizacijas); await _context.SaveChangesAsync(); var art_OrganizDTO = _mapper.Map <Art_OrganizDTO>(organizacijas); art_OrganizDTO.DAT_MOD = DateTime.Now; return(new CreatedAtRouteResult("getArt_Organiz", new { art_OrganizDTO.ID }, art_OrganizDTO)); // šeit vajag, lai ņem vērā to, ka ID ģenerējas DB. //https://docs.microsoft.com/en-us/ef/core/saving/explicit-values-generated-properties } }