public int Create(ToDoCreate request) { using (var con = GetConnection()) { var cmd = con.CreateCommand(); cmd.CommandText = "ToDo_Create"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@task", request.Task); cmd.Parameters.Add("@Id", SqlDbType.Int).Direction = ParameterDirection.Output; cmd.ExecuteNonQuery(); return((int)cmd.Parameters["@Id"].Value); } }
public bool CreateToDo(ToDoCreate model) { var entity = new ToDo() { OwnerID = _userID, Title = model.Title, Details = model.Details, GroupID = model.GroupID, IsDone = false, CreatedUtc = DateTimeOffset.Now }; using (var ctx = new ApplicationDbContext()) { ctx.ToDos.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(ToDoCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateToDoService(); if (service.CreateToDo(model)) { TempData["SaveResult"] = "Your note was created."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Note could not be created."); ViewBag.GroupID = new SelectList(db.Groups, "GroupID", "GroupName"); return(View(model)); }
public int Create(ToDoCreate model) { return(toDoService.Create(model)); }