public void Save(SavePostRequestModel request) { string sQuery = "INSERT INTO Posts VALUES(GETDATE(),GETDATE(),0, @Title, @text, @UserId); SELECT CAST(SCOPE_IDENTITY() as int)"; var id = sqlGateway.QueryFirst <int>(sQuery, request); foreach (var item in request.CategorieIds) { string queryForCategories = "INSERT INTO CategoriesPosts(CategoryId,PostId) VALUES(@categoryId, @postId)"; sqlGateway.Execute(queryForCategories, new { @categoryId = item, @postId = id }); } }
public ActionResult Get(SavePostRequestModel requestModel) { try { postRepository.Save(requestModel); return(Ok("Kaydedildi.")); } catch (Exception ex) { return(BadRequest(ex)); } }