public IActionResult Edit(int id) { if (id == 0) { return(NotFound()); } Platform platform = platformService.GetByID(id); if (platform == null) { return(NotFound()); } PlatformEditViewModel viewModel = new PlatformEditViewModel(); viewModel.Platform = platform; viewModel.PlatformTypes = platformTypeService.GetAll().Select(x => new SelectListItem { Text = x.Name, Value = x.ID.ToString() }).ToList(); viewModel.PlatformTypeID = platform.PlatformTypeID ?? null; return(View(viewModel)); }
public IActionResult Edit(PlatformEditViewModel viewModel) { Platform platform = platformService.GetByID(viewModel.Platform.ID); platform.Name = viewModel.Platform.Name; platform.PlatformTypeID = viewModel.Platform.PlatformTypeID ?? null; platformService.Update(platform); return(RedirectToAction("Details", platform)); }
public async Task<IActionResult> UpdatePlatform([FromBody]PlatformEditViewModel model) { Platform platform = await DataContext.Store.GetOneAsync<Platform>(p => p.Id == model.Id); if (platform == null) return NotFound("No platform exists with the given Id"); platform.Update(Mapper.Map<Platform>(model)); if (!await DataContext.Store.UpdateOneAsync(platform)) return BadRequest("An error occured while updating the platform"); return Ok(); }
public async Task<ActionResult> Edit(PlatformEditViewModel model) { if (ModelState.IsValid) { var result = await PlatformService.UpdatePlatform(model); if (result.Succeeded) { return RedirectToAction("Index"); } else { AddModelErrors(result.Errors); return View("Edit", model); } } return View("Edit", model); }
/// <summary> /// Készít egy új platformot /// </summary> /// <param name="model">Az új platform modelje</param> /// <returns></returns> public async Task<IServiceResult> CreatePlatform(PlatformEditViewModel model) { var result = new ServiceResult<PlatformEditViewModel>(); try { await TestPlatformStore.InsertAsync(Mapper.Map<PlatformEditViewModel, Platform>(model)); } catch (Exception e) { Log.Error(e.Message, e); result.AddError("", e.Message); } return result; }