Ejemplo n.º 1
0
        public void DeleteDetailImage(int?id)
        {
            CarDetailImage detailImage = _context.CarDetailImages.Where(cd => cd.Id == id).FirstOrDefault();

            RemovePhoto(_env.WebRootPath, detailImage.ImageUrl);
            _context.CarDetailImages.Remove(detailImage);
            _context.SaveChanges();
        }
Ejemplo n.º 2
0
 public IActionResult Chat(int?id)
 {
     if (User.Identity.IsAuthenticated && User.IsInRole("moderator"))
     {
         if (id == null || !_context.Orders.Any(o => o.Id == id))
         {
             return(PartialView("ErrorPage"));
         }
         if (!_context.Chats.Any(c => c.OrderId == id))
         {
             Chat newChat = new Chat
             {
                 OrderId = (int)id,
                 To      = _context.Orders.Where(o => o.Id == id).Include(o => o.Advertisement).FirstOrDefault().Advertisement.ApplicationUserId,
             };
             _context.Chats.Add(newChat);
             _context.SaveChanges();
         }
         ViewBag.Moderator = true;
         ChatModeratorVM vM = new ChatModeratorVM {
             ApplicationUser = _context.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(),
             ChatMessages    = _context.ChatMessages.Where(cm => cm.Chat.OrderId == id).Include(cm => cm.Chat).Include(cm => cm.Message).Include(cm => cm.Chat.Order).OrderBy(cm => cm.Message.Date)
         };
         return(View(vM));
     }
     ViewBag.IsHeaderNonVisible = true;
     return(Redirect("/account/login"));
 }
Ejemplo n.º 3
0
 public IActionResult Delete(int?id)
 {
     if (User.Identity.IsAuthenticated && User.IsInRole("member"))
     {
         if (id == null || !_context.AdvertisementMessages.Any(adM => adM.Id == id))
         {
             return(PartialView("ErrorPage"));
         }
         AdvertisementMessage advertisementMessage = _context.AdvertisementMessages.Where(adM => adM.Id == id).Include(adM => adM.Message).FirstOrDefault();
         _context.Messages.Remove(advertisementMessage.Message);
         _context.AdvertisementMessages.Remove(advertisementMessage);
         _context.SaveChanges();
         return(RedirectToAction(nameof(Index)));
     }
     ViewBag.IsHeaderNonVisible = true;
     return(Redirect("/account/login"));
 }
Ejemplo n.º 4
0
        public IActionResult DetailsPost(int id, Review review)
        {
            if (!_context.Advertisements.Any(ad => ad.Id == id && ad.IsVerified))
            {
                return(PartialView("ErrorPage"));
            }
            if (!ModelState.IsValid)
            {
                return(PartialView("ErrorPage"));
            }
            Review newReview = new Review
            {
                Date            = DateTime.Now,
                CustomerName    = review.CustomerName,
                Email           = review.Email,
                AdvertisementId = id,
                Comment         = review.Comment
            };

            _context.Reviews.Add(newReview);
            _context.SaveChanges();

            return(RedirectToAction(nameof(Details)));
        }