Пример #1
0
        public ActionResult Index(FormCollection collection)
        {
            string currentuser = User.Identity.GetUserId();

            //Do stuff with formCollection
            Debug.WriteLine("Index-contrller with formcollection called");


            if (ModelState.IsValid)
            {
                foreach (string _formData in collection)
                {
                    string id = collection[_formData];
                    Debug.WriteLine("Inbox controller MarkAsRead vill göra en int av detta: " + id);
                    int       idnumber = Convert.ToInt32(id);
                    ReadEntry entry    = db.ReadEntries.Where(r => r.Message.Id == idnumber && r.Receiver.Equals(currentuser)).Single();
                    if (!entry.hasRead())
                    {
                        entry.FirstReadTime = System.DateTime.Now;
                    }
                }

                db.SaveChanges();
            }

            return(RedirectToAction("Index", "Inbox"));
        }
Пример #2
0
        /// <summary>
        /// Shows detailed page of a specific message
        /// </summary>
        /// <param name="id">Message id</param>
        /// <returns></returns>
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            string           currentuser = User.Identity.GetUserId();
            Message          message     = db.Messages.Find(id);
            MessageViewModel messageCopy = MessageController.MessageToViewModel(message);
            //set read entry to viewed
            ReadEntry entry = db.ReadEntries.Where(r => r.Message.Id == id && r.Receiver.Equals(currentuser)).Single();

            if (!entry.hasRead())
            {
                entry.FirstReadTime = System.DateTime.Now;
                db.SaveChanges();
                Debug.WriteLine("time read at " + entry.FirstReadTime);
            }


            if (messageCopy == null)
            {
                return(HttpNotFound());
            }
            return(View(messageCopy));
        }