示例#1
0
 //
 // GET: /Message/
 public ActionResult PostMessage(int UserGetId)
 {
     Message model = new Message();
     UsersContext db = new UsersContext();
     List<UserData> TempList = new List<UserData>();
     TempList = db.UsersData.ToList();
     UserData PostUser = new UserData();
     for (int i = 0; i < TempList.Count; i++)
     {
         if (TempList[i].UserProfile.UserId == WebSecurity.CurrentUserId)
         {
             PostUser = TempList[i];
             break;
         }
     }
     model.UserGet = db.UserProfiles.Find(UserGetId);
     model.UserPost = PostUser.UserProfile;
     return View(model);
 }
示例#2
0
 public ActionResult PostMessage(Message model, int UserGetId, string returnUrl)
 {
     UsersContext db = new UsersContext();           
     model.UserGet = db.UserProfiles.Find(UserGetId);
     model.UserPost = db.UserProfiles.Find(WebSecurity.CurrentUserId);
     model.Time = DateTime.Now;
     model.IsRead = false;
     // Обнуляем ID юзера, т.к. чудесным образом вместо модели получателя
     // в контроллер приходит ID получателя, причем он записывается в поле ID модели
     // чудеса да и только
     model.Id = 0;
     int CurrentUserPageId = model.UserGet.UserId;
     db.Messages.Add(model);
     db.SaveChanges();
     return Redirect(returnUrl);
     //Uri MyUrl = Request.UrlReferrer;
     //if (MyUrl.LocalPath == "/Message/Dialog")
     //    return RedirectToAction("Dialog", "Message", new { UserId = UserGetId });
     //else
     //    return RedirectToAction("Index", "Users", new { id = CurrentUserPageId });
     
 }