public IActionResult Transfer(EduPointTransferFormViewModel pointForm) { if (ModelState.IsValid) { EduPoint point = pointMapper.MapEduPointTransferFormViewModelToModel(pointForm); if (pointForm.EduPointViewModel.Id.HasValue) { eduPointService.ChangePoint(point); } else { User sender = userService.GetUser(this.User); eduPointService.CreatePoint(point, sender); } eduPointService.SaveChanges(); return(RedirectToAction("Index")); } else { pointMapper.FillEduPointTransferFormViewModel(pointForm); return(View(pointForm)); } }
public ViewResult Edit(int id) { EduPoint point = eduPointService.GetPoint(id); EduPointTransferFormViewModel pointForm = pointMapper.MapEduPointModelToTransferFormViewModel(point); return(View("Transfer", pointForm)); }
public EduPointTransferFormViewModel FillEduPointTransferFormViewModel(EduPointTransferFormViewModel pointForm) { pointForm.SetUsers(userService.GetUsers()); pointForm.SetCategories(pointCategoryService.GetCategories()); pointForm.EduPointViewModel.Sender = userService.GetUser(pointForm.EduPointViewModel.Sender.Id); return(pointForm); }
public EduPointTransferFormViewModel CreateEduPointTransferFormViewModel(ClaimsPrincipal identity) { IEnumerable <EduPointCategory> categories = pointCategoryService.GetCategories(); IEnumerable <User> users = userService.GetUsers(); var eduPointTransferFormViewModel = new EduPointTransferFormViewModel(categories, users); eduPointTransferFormViewModel.EduPointViewModel = new EduPointViewModel(); eduPointTransferFormViewModel.EduPointViewModel.Sender = userService.GetUser(identity); return(eduPointTransferFormViewModel); }
public EduPointTransferFormViewModel MapEduPointModelToTransferFormViewModel(EduPoint point) { IEnumerable <EduPointCategory> categories = pointCategoryService.GetCategories(); IEnumerable <User> users = userService.GetUsers(); var eduPointTransferFormViewModel = new EduPointTransferFormViewModel(categories, users); eduPointTransferFormViewModel.EduPointViewModel = MapEduPointModelToViewModel(point); eduPointTransferFormViewModel.EduPointViewModel.Sender = point.Sender; return(eduPointTransferFormViewModel); }
public EduPoint MapEduPointTransferFormViewModelToModel(EduPointTransferFormViewModel pointForm) { EduPoint point; if (pointForm.EduPointViewModel.Id.HasValue) { point = pointService.GetPoint(pointForm.EduPointViewModel.Id.Value); } else { point = new EduPoint(); } point.Category = pointCategoryService.GetCategory(pointForm.EduPointViewModel.CategoryId.Value); point.Receiver = userService.GetUser(pointForm.EduPointViewModel.ReceiverId); point.Description = pointForm.EduPointViewModel.Description; point.Amount = pointForm.EduPointViewModel.Amount; return(point); }
public ViewResult Transfer() { EduPointTransferFormViewModel pointForm = pointMapper.CreateEduPointTransferFormViewModel(this.User); return(View("Transfer", pointForm)); }