public IActionResult CreateColumns(int accountId, int formId, [FromBody] ICollection <ColumnForCreationDto> columns) { if (columns == null) { return(BadRequest()); } //if (column..Description == form.Title) //{ // ModelState.AddModelError("Description", "The provided description should be different from the title."); //} if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_accountRepository.AccountExists(accountId)) { return(NotFound("Account Id[" + accountId + "] does not exist")); } if (!_formRepository.FormExists(formId)) { return(NotFound("Form Id[" + formId + "] does not exist")); } //var finalColumn = Mapper.Map<Entities.Column>(column); var finalColumns = Mapper.Map <ICollection <Entities.Column> >(columns); _formRepository.AddColumnsForForm(formId, finalColumns); //Entities.Column s = new Entities.Column(); //s.Id //if (context.ObjectStateManager.GetObjectStateEntry(myEntity).State == EntityState.Detached) //{ // context.MyEntities.AddObject(myEntity); //} //// Attached object tracks modifications automatically //_formRepository.SaveChanges(); try { if (!_formRepository.Save()) { return(StatusCode(500, "A problem happened while handling your request.")); } } catch (Microsoft.EntityFrameworkCore.DbUpdateException dbEx) { return(BadRequest("Error saving. Please make sure there are no duplicate values.")); } catch (Exception ex) { return(StatusCode(500, "A problem happened while handling your request.")); } return(Ok()); }