コード例 #1
0
 public ActionResult Conversation(int?AdvertId, int?UserA, int?UserB)
 {
     if (TempData["SizeError"] != null)
     {
         ViewBag.Error = "Maksymalny rozmiar zdjęć to 2MB";
         TempData.Remove("SizeError");
     }
     if (TempData["FormatError"] != null)
     {
         ViewBag.Error = "Użyto nieobsługiwanego formatu zdjęć. Dozwolone formaty: .jpg .jpeg .png";
         TempData.Remove("FormatError");
     }
     if (AdvertId != null && UserA != null && UserB != null)
     {
         if (Session["ID"] != null)
         {
             int userID = Convert.ToInt32(Session["ID"]);
             if (userID != UserA || userID != UserB)
             {
                 if (userID == UserA)
                 {
                     messageModel.LoggedUser             = new UserRepository().GetUserData((int)UserA);
                     messageModel.SecondConversationUser = new UserRepository().GetUserData((int)UserB);
                     messageModel.LoggedUserAdverts      = new AdvertRepository().GetUserAdverts((int)UserA).ToList();
                 }
                 if (userID == UserB)
                 {
                     messageModel.LoggedUser             = new UserRepository().GetUserData((int)UserB);
                     messageModel.SecondConversationUser = new UserRepository().GetUserData((int)UserA);
                     messageModel.LoggedUserAdverts      = new AdvertRepository().GetUserAdverts((int)UserB).ToList();
                 }
                 messageModel.CoversationMessages = new UserRepository().GetConversation((int)AdvertId, (int)UserA, (int)UserB).ToList();
                 messageModel.Images = new UserRepository().GetConversationImages((int)AdvertId, (int)UserA, (int)UserB).ToList();
                 messageModel.MessageAdvertDetails = db.ADVERTS.Where(x => x.ID == (int)AdvertId).ToList();
                 foreach (var item in messageModel.CoversationMessages)
                 {
                     var msgID = (item.ID);
                     if (item.MSG_TO == userID)
                     {
                         var     ID          = msgID;
                         MESSAGE MsgToChange = new UserRepository().GetMessage(ID);
                         MsgToChange.IS_READ         = true;
                         db.Entry(MsgToChange).State = System.Data.Entity.EntityState.Modified;
                         db.SaveChanges();
                     }
                 }
                 ;
                 return(View(messageModel));
             }
             return(RedirectToAction("messages", "User"));
         }
         return(RedirectToAction("Logowanie", "Home"));
     }
     else
     {
         return(RedirectToAction("Index", "Home"));
     }
 }
コード例 #2
0
 public ActionResult EditAdvertisement(ADVERTS obj)
 {
     if (ModelState.IsValid)
     {
         obj.IS_HIDDEN       = false;
         db.Entry(obj).State = System.Data.Entity.EntityState.Modified;
         // model.Categories = addingAdsRepository.GetList();
         //model.CategoryID = -1;
         db.SaveChanges();
         ViewBag.Message = "Zaktualizowano ogłoszenie";
         int uID = Convert.ToInt32(Session["ID"]);
         displayRepository.LoggedUser = advertRepository.GetUserData(uID);
         return(RedirectToAction("MojeOgloszenia", "adverts"));
     }
     else
     {
         ViewBag.Message = "Popraw dane";
         return(View());
     }
 }