public ActionResult Create(Task task) { if (ModelState.IsValid) { Db.Add(task); return(RedirectToAction("Overview")); } return(View(task)); }
//OBRISI //On POst prima zadatak kojeg editiramo u POST FORMI, jer smo stavili da je MYTASK = BindProperty, tako da smo "uzeli" taj zadatak i dalje s njim // mozemo baratati u OnPost metodi, tako cu isto napraviti s "work" gumbom, koji ce mi biti on post :) public IActionResult OnPost() { SelectType = htmlHelper.GetEnumSelectList <TaskType>(); if (ModelState.IsValid) { if (MyTask.Id > 0) { MyTask = taskData.Update(MyTask); TempData["Message"] = "Task updated!"; } else { MyTask = taskData.Add(MyTask); TempData["Message"] = "Task saved!"; } //taskData.Commit(); return(RedirectToPage("./Detail", new { taskId = MyTask.Id })); } return(Page()); }
public async Task <ActionResult <TaskModel> > Post(TaskModel model) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var task = _mapper.Map <Test.Core.Task>(model); _repository.Add(task); if (await _repository.SaveChangesAsync() == 1) { return(Created($"/api/task/{task.Id}", _mapper.Map <TaskModel>(task))); } } catch (Exception) { return(this.StatusCode(StatusCodes.Status500InternalServerError)); } return(BadRequest()); }
public IActionResult OnPost() { if (!ModelState.IsValid) { Status = _htmlHelper.GetEnumSelectList <TaskStatus>(); Priority = _htmlHelper.GetEnumSelectList <TaskPriority>(); return(Page()); } if (Task.Id > 0) { _taskData.Update(Task); TempData["Message"] = "Task updated!"; } else { _taskData.Add(Task); TempData["Message"] = "Task added!"; } _taskData.Commit(); return(RedirectToPage("./Detail", new { taskId = Task.Id })); }