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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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));
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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));
        }
Beispiel #7
0
        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));
        }
Beispiel #8
0
        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());
 }