Exemple #1
0
        public async Task <IActionResult> Create(IFormCollection data, [Bind("Id,Content,PostId,CreatorId,CreationDate,LastEditionDate")] Comment comment)
        {
            if (ModelState.IsValid)
            {
                var id = new byte[20];
                HttpContext.Session.TryGetValue("id", out id);
                string str    = System.Text.Encoding.UTF8.GetString(id);
                int    userId = int.Parse(str);
                comment.CreationDate    = DateTime.Now;;
                comment.LastEditionDate = DateTime.Now;
                comment.CreatorId       = userId;
                comment.PostId          = comment.Id;
                comment.Content         = data["Content"];
                comment.Id = 0;
                _context.Add(comment);
                System.Diagnostics.Debug.WriteLine(comment.Id + " id");
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            comment.CreationDate    = DateTime.Now;
            comment.LastEditionDate = DateTime.Now;
            ViewData["CreatorId"]   = new SelectList(_context.User, "Id", "Nick", comment.CreatorId);
            ViewData["PostId"]      = new SelectList(_context.Post, "Id", "Title", comment.PostId);
            return(View(comment));
        }
        public async Task <IActionResult> Create([Bind("Id,Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Exemple #3
0
        public async Task <IActionResult> Create([Bind("Id,Login,Password,Nick,LastPasswordChangedDate,RegistrationDate")] User user)
        {
            if (ModelState.IsValid)
            {
                user.LastPasswordChangedDate = DateTime.Now;
                user.RegistrationDate        = DateTime.Now;
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
Exemple #4
0
        public async Task <IActionResult> Create([Bind("Id,TagId,PostId")] PostTag postTag)
        {
            if (ModelState.IsValid)
            {
                _context.Add(postTag);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PostId"] = new SelectList(_context.Post, "Id", "Title", postTag.PostId);
            ViewData["TagId"]  = new SelectList(_context.Tag, "Id", "Name", postTag.TagId);
            return(View(postTag));
        }
        public async Task <IActionResult> Create([Bind("Id,UserId,CommentId,DateOfAddition")] Point point)
        {
            if (ModelState.IsValid)
            {
                point.DateOfAddition = DateTime.Now;
                _context.Add(point);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            ViewData["CommentId"] = new SelectList(_context.Comment, "Id", "Title", point.CommentId);
            ViewData["UserId"]    = new SelectList(_context.User, "Id", "Nick", point.UserId);
            return(View(point));
        }