public async Task <IActionResult> PutLike(Guid id, Like like)
        {
            if (id != like.LikeId)
            {
                return(BadRequest());
            }

            _context.Entry(like).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LikeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #2
0
        public async Task <IActionResult> PutAppUser(string id, AppUser appUser)
        {
            if (id != appUser.Id)
            {
                return(BadRequest());
            }

            _context.Entry(appUser).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AppUserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutInterest(int id, Interest interest)
        {
            if (id != interest.InterestId)
            {
                return(BadRequest());
            }

            _context.Entry(interest).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!InterestExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #4
0
        public async Task <IActionResult> Create([Bind("FirstName,LastName,Id,UserName,NormalizedUserName,Email,NormalizedEmail,EmailConfirmed,PasswordHash,SecurityStamp,ConcurrencyStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEnd,LockoutEnabled,AccessFailedCount")] AppUser appUser)
        {
            if (ModelState.IsValid)
            {
                _context.Add(appUser);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(appUser));
        }
Пример #5
0
        // Like/Dislike
        public async Task <IActionResult> Create(int PostId)
        {
            var UserId = _userManager.GetUserId(User);

            //Like likeExists = await _context.Likes.FindAsync(UserId, PostId);
            Like likeExists = _context.Likes.Where(l => l.UserId == UserId && l.PostId == PostId).FirstOrDefault();

            if (ModelState.IsValid)
            {
                if (likeExists == null)
                {
                    Like like = new Like {
                        UserId = UserId, PostId = PostId
                    };
                    _context.Add(like);
                }
                else
                {
                    _context.Remove(likeExists);
                }

                await _context.SaveChangesAsync();
            }

            return(RedirectToAction("Index", "Posts"));
        }
Пример #6
0
        public async Task <IActionResult> Create([Bind("PostId,Text,TypeId,ImageFile")] Post post)
        {
            if (ModelState.IsValid)
            {
                string wwwroot = _hostEnvironment.WebRootPath;

                AppUser AppUser = await _userManager.GetUserAsync(HttpContext.User);

                post.Owner       = AppUser;
                post.OwnerId     = AppUser.Id;
                post.DateCreated = DateTime.Now;

                if (post.ImageFile != null)
                {
                    string fileName  = Path.GetFileNameWithoutExtension(post.ImageFile.FileName);
                    string extension = Path.GetExtension(post.ImageFile.FileName);
                    post.Image = "postImage" + extension;
                }

                _context.Add(post);
                await _context.SaveChangesAsync();

                if (post.ImageFile != null)
                {
                    string path = Path.Combine(wwwroot, "userFiles", post.OwnerId, post.PostId + "", post.Image);
                    Directory.CreateDirectory(Path.GetDirectoryName(path));
                    using (var fileStream = new FileStream(path, FileMode.Create))
                    {
                        await post.ImageFile.CopyToAsync(fileStream);
                    }
                }

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

            ViewData["TypeId"] = new SelectList(_context.Interests, "InterestId", "Name", post.TypeId);

            return(View(post));
        }