Пример #1
0
        public ActionResult Create(CardFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Professions = _context.Professions.ToList();
                return(View("CardForm", viewModel));
            }
            //var userProfessionalsId = User.Identity.GetUserId();
            //var userProfessionals = _context.Users.Single(u => u.Id == userProfessionalsId);
            //var profession = _context.Professions.Single(u => u.Id == viewModel.Profession);
            var card = new Card
            {
                UserProfessionalsId = User.Identity.GetUserId(),
                DateTime            = viewModel.GetDateTime(),
                ProfessionId        = viewModel.Profession,
                Description         = viewModel.Description
            };

            _context.Cards.Add(card);
            _context.SaveChanges();
            return(RedirectToAction("Mine", "Card"));
        }
Пример #2
0
        public ActionResult Update(CardFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Professions = _context.Professions.ToList();
                return(View("CardForm", viewModel));
            }
            //var userProfessionalsId = User.Identity.GetUserId();
            //var userProfessionals = _context.Users.Single(u => u.Id == userProfessionalsId);
            //var profession = _context.Professions.Single(u => u.Id == viewModel.Profession);
            var userId = User.Identity.GetUserId();
            var card   = _context.Cards
                         .Include(g => g.Followers.Select(a => a.Follower))
                         .Single(g => g.Id == viewModel.Id && g.UserProfessionalsId == userId);

            card.Modify(viewModel.GetDateTime(), viewModel.Description, viewModel.Profession);

            //card.Description = viewModel.Description;
            //card.DateTime = viewModel.GetDateTime();
            //card.ProfessionId = viewModel.Profession;

            _context.SaveChanges();
            return(RedirectToAction("Mine", "Card"));
        }