public async Task<ActionResult> Create(TariffViewModel method) { if (ModelState.IsValid) { await _tariffService.CreateAsync(new Tariff() { Name = method.Name, Cost = method.Cost, Messages = method.Messages, Minutes = method.Minutes }); return RedirectToAction("Index"); } return View(method); }
public async Task<ActionResult> Edit(int id) { var tariff = await _tariffService.GetByIdAsync(id); if (tariff == null) { return HttpNotFound("tariff not found"); } var tariffViewModel = new TariffViewModel() { Id = tariff.Id, Name = tariff.Name, Cost = tariff.Cost, Messages = tariff.Messages, Minutes = tariff.Minutes }; return View(tariffViewModel); }
public async Task<ActionResult> Edit(TariffViewModel tariffViewModel) { if (ModelState.IsValid) { var tariff = await _tariffService.GetByIdAsync(tariffViewModel.Id); if (tariff == null) { return HttpNotFound("tariff not found"); } tariff.Cost = tariffViewModel.Cost; tariff.Name = tariffViewModel.Name; tariff.Messages = tariffViewModel.Messages; tariff.Minutes = tariffViewModel.Minutes; await _tariffService.UpdateAsync(tariff); return RedirectToAction("Index"); } return View(tariffViewModel); }