public ActionResult Save(InstructionPageViewModel instructionPageViewModel) { var instructionId = instructionPageViewModel.InstructionId; var instructionPageDto = Mapper.Map <InstructionPageDto>(instructionPageViewModel); if (!ModelState.IsValid) { instructionPageViewModel = new InstructionPageViewModel(); instructionPageViewModel.InstructionId = instructionId; instructionPageViewModel.PartDtos = partService.GetAll(); instructionPageViewModel.InstructionDtos = instructionService.GetAll(); return(View("InstructionPageForm", instructionPageViewModel)); } if (instructionPageDto.Id == 0) { var path = fileManager.GeneratePictureName("/Files/Pages/"); instructionPageDto.PictureId = path; instructionPageService.Add(instructionPageDto); if (instructionPageViewModel.Picture.Upload != null) { instructionPageViewModel.Picture.Upload .SaveAs(Server.MapPath(path)); } } else { var pictureLink = instructionPageDto.PictureId; bool delete = true; if (pictureLink == null) { instructionPageDto.PictureId = fileManager.GeneratePictureName("/Files/Pages/"); delete = false; } instructionPageService.Edit(instructionPageDto); if (instructionPageViewModel.Picture.Upload != null) { if (delete) { var pathToPicture = Server.MapPath(pictureLink); if (fileManager.FileExists(pathToPicture)) { fileManager.Delete(pathToPicture); } } instructionPageViewModel.Picture.Upload .SaveAs(Server.MapPath(pictureLink)); } } return(RedirectToAction("Details", "Instructions", new { @instructionDtoId = instructionId })); }
public ActionResult New(int instructionId) { var instructionPageViewModel = new InstructionPageViewModel(); instructionPageViewModel.InstructionId = instructionId; instructionPageViewModel.PartDtos = partService.GetAll(); instructionPageViewModel.InstructionDtos = instructionService.GetAll(); return(View("InstructionPageForm", instructionPageViewModel)); }
protected override void OnAppearing() { base.OnAppearing(); BindingContext = new InstructionPageViewModel(); }