示例#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> Create([Bind(userString)] User user, IFormFile img)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (img != null)
                    {
                        if (img.Length > 0)
                        {
                            using (var ms = new MemoryStream())
                            {
                                img.CopyTo(ms);
                                var fileBytes = ms.ToArray();
                                user.Avatar = fileBytes;
                            }
                        }
                    }

                    user.Role = "normal";
                    _context.Add(user);
                    await _context.SaveChangesAsync();

                    HttpContext.Session.SetString("sName", user.Name);
                    HttpContext.Session.SetString("sEmail", user.Email);
                    HttpContext.Session.SetString("sRole", user.Role);
                    HttpContext.Session.SetString("sId", user.ID.ToString());
                    HttpContext.Session.Remove("userExist");
                    var task = Task.Run(async() =>
                    {
                        using (var es = _emailService.SendEmailAsync(user.Email, "You have been registered in HouseRent.", $"Login: {user.Email}\nPassword: {user.Password}"))
                        {
                            await es;
                        }
                    });
                    return(RedirectToAction(nameof(Index)));
                }
                catch
                {
                    HttpContext.Session.SetString("userExist", user.Email + " Already Exist. Go to Login Page.");
                    return(View(user));
                }
            }
            return(View(user));
        }
示例#4
0
        public async Task <IActionResult> Create([Bind(userString)] User user, IFormFile img)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    //for image : if given an image or not
                    if (img != null)
                    {
                        if (img.Length > 0)
                        {
                            using (var ms = new MemoryStream())
                            {
                                img.CopyTo(ms);
                                var fileBytes = ms.ToArray();
                                user.Avatar = fileBytes;
                            }
                        }
                    }

                    user.Role = "normal"; //others user are either admin or banned
                    _context.Add(user);
                    await _context.SaveChangesAsync();

                    HttpContext.Session.SetString("sName", user.Name);
                    HttpContext.Session.SetString("sEmail", user.Email);
                    HttpContext.Session.SetString("sRole", user.Role);
                    HttpContext.Session.SetString("sId", user.ID.ToString());
                    HttpContext.Session.Remove("userExist");
                    return(RedirectToAction(nameof(Index)));
                }
                catch
                {
                    HttpContext.Session.SetString("userExist", user.Email + " Already Exist. Go to Login Page.");
                    return(View(user));
                }
            }
            return(View(user));
        }