public IActionResult Post([FromBody] Tip tip) { if (!tip.IsValid()) { return(BadRequest("this does not seem to be a good tip :(")); } if (tip.Id != 0) { throw new InvalidOperationException("id > 0"); } tip.Id = _tipRepository.GetMaxId() + 1; _tipRepository.Insert(tip); return(this.CreatedAtRoute("GetTip", new { controller = "Tip", id = tip.Id }, tip)); }
public ActionResult Create([TipBinder(Fetch = false)] Tip tip) { if (ViewData.ModelState.IsValid && tip.IsValid()) { taskRepository.Get(tip.Task.Id).Tips.Add(tip); tipRepository.SaveOrUpdate(tip); Message = "Подсказка успешно создана."; return(this.RedirectToAction <TasksController>(c => c.Edit(tip.Task.Id))); } TipFormViewModel viewModel = TipFormViewModel.CreateTipFormViewModel(); viewModel.Tip = tip; return(View(viewModel)); }
public IActionResult Put(long id, [FromBody] Tip tip) { if (!tip.IsValid()) { return(BadRequest("this doesn not seem to be a good tip :(")); } if (tip.Id != id) { return(BadRequest()); } if (_tipRepository.Get(id) == null) { return(NotFound()); } _tipRepository.Update(tip); return(new NoContentResult()); }
public ActionResult Edit([TipBinder(Fetch = true)] Tip tip) { Tip tipToUpdate = tipRepository.Get(tip.Id); TransferFormValuesTo(tipToUpdate, tip); if (ViewData.ModelState.IsValid && tip.IsValid()) { Message = "Подсказка успешно изменена."; return(this.RedirectToAction <TasksController>(c => c.Edit(tip.Task.Id))); } else { tipRepository.DbContext.RollbackTransaction(); TipFormViewModel viewModel = TipFormViewModel.CreateTipFormViewModel(); viewModel.Tip = tip; return(View(viewModel)); } }