Пример #1
0
        public async Task <IActionResult> DoReview(Review review)
        {
            string usr = HttpContext.Session.GetString("sEmail");

            if (String.IsNullOrEmpty(usr))
            {
                return(RedirectToAction("Login", "Users"));
            }
            review.Reviewer = usr;

            var Reviewed = await _context.Review.SingleOrDefaultAsync(r => r.Reviewer == usr && r.AdvertiseID == review.AdvertiseID);

            if (Reviewed == null)
            {
                _context.Add(review);
                await _context.SaveChangesAsync();
            }
            else
            {
                Reviewed.ReviewStar = review.ReviewStar;
                _context.Update(Reviewed);
                await _context.SaveChangesAsync();
            }

            return(RedirectToAction("Details", new { id = review.AdvertiseID }));
        }
        public async Task <IActionResult> DoReview(Review review)
        {
            string usr = HttpContext.Session.GetString("sEmail");

            //this means u cannot review without being logged in
            if (String.IsNullOrEmpty(usr))
            {
                return(RedirectToAction("Login", "Users"));
            }
            review.Reviewer = usr;

            //checking if user reviewed once or not...
            var Reviewed = await _context.Review.SingleOrDefaultAsync(r => r.Reviewer == usr && r.AdvertiseID == review.AdvertiseID);

            if (Reviewed == null)
            {
                //if user reviewing for an advertise for the first time
                _context.Add(review);
                await _context.SaveChangesAsync();
            }
            else
            {
                //if already reviewed it, but want to change review
                Reviewed.ReviewStar = review.ReviewStar;
                _context.Update(Reviewed);
                await _context.SaveChangesAsync();
            }


            return(RedirectToAction("Details", new { id = review.AdvertiseID }));
        }
Пример #3
0
        public async Task <IActionResult> Edit(int id, [Bind(userString)] User user)
        {
            if (id != user.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(user);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }