Ejemplo n.º 1
0
        public ActionResult Create()
        {
            var viewModel = new CardFormViewModel
            {
                Professions = _context.Professions.ToList(),
                Heading     = "Add a card"
            };

            return(View("CardForm", viewModel));
        }
Ejemplo n.º 2
0
        public ActionResult Edit(int id)
        {
            var userid = User.Identity.GetUserId();
            var card   = _context.Cards.Single(g => g.Id == id && g.UserProfessionalsId == userid);

            var viewModel = new CardFormViewModel
            {
                Professions = _context.Professions.ToList(),
                Id          = card.Id,
                Date        = card.DateTime.ToString("d MMM yyyy"),
                Time        = card.DateTime.ToString("HH:mm"),
                Profession  = card.ProfessionId,
                Description = card.Description,
                Heading     = "Edit a card"
            };

            return(View("CardForm", viewModel));
        }
Ejemplo n.º 3
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"));
        }
Ejemplo n.º 4
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"));
        }