private static Friend ViewModelToDomain(FriendFormViewModel friendFormViewModel) { return(new Friend { Address = friendFormViewModel.Address, Email = friendFormViewModel.Email, FullName = friendFormViewModel.FullName, TelephoneNumber = friendFormViewModel.TelephoneNumber }); }
public async void UpdateById(Guid id, FriendFormViewModel friendFormViewModel) { var friend = await _friendRepository.GetAsync(id); if (friend == null) { throw new Exception("No friend found."); } friend.Address = friendFormViewModel.Address; friend.Email = friendFormViewModel.Email; friend.FullName = friendFormViewModel.FullName; friend.TelephoneNumber = friendFormViewModel.TelephoneNumber; _friendRepository.Update(friend); }
public void AddTest() { var mock = new Mock <IFriendService>(); var friendFormViewModel = new FriendFormViewModel { Address = "1", Email = "*****@*****.**", FullName = "Fulano", TelephoneNumber = "1234" }; mock.Setup(e => e.Add(friendFormViewModel)); mock.Object.Add(friendFormViewModel); }
public ViewResult NewFriend() { //get a list of the meal types first var mealTypes = _context.MealPlanTypes.ToList(); var goalSetting = _context.GoalSettings.ToList(); var viewModel = new FriendFormViewModel { Friend = new Friend(), MealPlanType = mealTypes, GoalSettings = goalSetting }; return(View("FriendForm", viewModel)); }
public void UpdateByIdTest() { var mock = new Mock <IFriendService>(); var guid = Guid.NewGuid(); var friendFormViewModel = new FriendFormViewModel { Address = "1", Email = "*****@*****.**", FullName = "Fulano", TelephoneNumber = "1234" }; mock.Setup(e => e.UpdateById(guid, friendFormViewModel)); mock.Object.UpdateById(guid, friendFormViewModel); }
public ActionResult FriendProfile(int id) { var friend = _context.Friends.SingleOrDefault(f => f.Id == id); if (friend == null) { return(HttpNotFound()); } var viewModel = new FriendFormViewModel { Friend = friend, MealPlanType = _context.MealPlanTypes.ToList() }; return(View("FriendProfile", viewModel)); }
public ActionResult Edit(int id) { var friend = _context.Friends.SingleOrDefault(f => f.Id == id); if (friend == null) { return(HttpNotFound()); //standard 404 error } var FriendViewModel = new FriendFormViewModel() { Friend = friend, MealPlanType = _context.MealPlanTypes.ToList() }; return(View("FriendForm", FriendViewModel)); }
public ActionResult Save(Friend friend) { if (!ModelState.IsValid) { var viewModel = new FriendFormViewModel { Friend = friend, MealPlanType = _context.MealPlanTypes.ToList() }; return(View("FriendFrom", viewModel)); } if (friend.Id == 0) { //in memory only _context.Friends.Add(friend); } else { var friendDbContext = _context.Friends.Single(f => f.Id == friend.Id); friendDbContext.Name = friend.Name; friendDbContext.Birthdate = friend.Birthdate; friendDbContext.MealPlanType = friend.MealPlanType; friendDbContext.IsCompetingWithOtherUsers = friend.IsCompetingWithOtherUsers; } try { _context.SaveChanges(); } catch (DbEntityValidationException e) { Console.WriteLine(e); } //rederict user back to list of friends //"Index" in Friends Controller return(RedirectToAction("Index", "Friend")); }
public void Add(FriendFormViewModel friendFormViewModel) { _friendRepository.Add(ViewModelToDomain(friendFormViewModel)); }
public IActionResult Update(Guid id, FriendFormViewModel model) { _logger.LogInformation("Started method Update"); _friendService.UpdateById(id, model); return(Ok()); }
public IActionResult Add(FriendFormViewModel model) { _logger.LogInformation("Started method Add"); _friendService.Add(model); return(Ok()); }