Exemple #1
0
        public ActionResult CreateOk(Message model, string tags)
        {
            if (model.Text == model.Title)
            {
                ModelState.AddModelError("Description", "Text and Title should have different values!");
            }

            Message message = new Message()
            {
                Title = model.Title,
                Text = model.Text,
                CreatedOn = DateTime.Now,
                Author = this.Data.Users.All().FirstOrDefault(
                x => x.UserName == this.HttpContext.User.Identity.Name)
            };

            string[] tagNames = tags.Split(',');
            foreach (var item in tagNames)
            {
                var current = this.Data.Tags.All().FirstOrDefault(x => item.ToLower() == x.Name);
                if (current == null)
                {
                    current = new Tag { Name = item.ToLower() };
                }

                message.Tags.Add(current);
            }

            this.Data.Messages.Add(message);
            this.Data.SaveChanges();
            return RedirectToAction("ByUser");
        }
        public ActionResult Create(Message message)
        {
            if (ModelState.IsValid)
            {
                db.Messages.Add(message);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(message);
        }
        public ActionResult SendMessage(MessageInputModel model)
        {
            if (this.ModelState.IsValid && this.ModelState != null)
            {
                var message = new Message()
                {
                    Content = model.Content,
                    CreatedOn = DateTime.Now,
                    Reciever = this.Data.Users.All().FirstOrDefault(u=>u.Id==model.RecieverId),
                    Sender = this.Data.Users.All().FirstOrDefault(u => u.Id == model.SenderId)

                };
                this.Data.Messages.Add(message);
                this.Data.SaveChanges();
            }
            return View(model);
        }
Exemple #4
0
        // The id parameter name should match the DataKeyNames value set on the control
        public void GridViewMessages_UpdateItem(int MessageId)
        {
            TwitterEntities context = new TwitterEntities();

            Twitter.Models.Message item = null;
            // Load the item here, e.g. item = MyDataLayer.Find(id);
            item = context.Messages.Find(MessageId);
            if (item == null)
            {
                // The item wasn't found
                ModelState.AddModelError("", String.Format("Item with id {0} was not found", MessageId));
                return;
            }
            TryUpdateModel(item);
            if (ModelState.IsValid)
            {
                context.SaveChanges();
                // Save changes here, e.g. MyDataLayer.SaveChanges();
            }
        }
Exemple #5
0
        // The id parameter name should match the DataKeyNames value set on the control
        public void GridViewMyMessages_UpdateItem(int MessageId)
        {
            TwitterEntities context = new TwitterEntities();

            Twitter.Models.Message item = null;
            // Load the item here, e.g. item = MyDataLayer.Find(id);

            item = context.Messages.FirstOrDefault(x => x.MessageId == MessageId);
            if (item == null)
            {
                // The item wasn't found
                ModelState.AddModelError("", String.Format("Item with id {0} was not found", MessageId));
                return;
            }
            TryUpdateModel(item);
            if (ModelState.IsValid)
            {
                // Save changes here, e.g. MyDataLayer.SaveChanges();
                try
                {
                    Verificator.ValidateMessage(item.MessageContent);
                    context.SaveChanges();
                    ErrorSuccessNotifier.AddInfoMessage("Message has been edited successfully");
                }
                catch (Exception ex)
                {
                    if (ex.Message != null)
                    {
                        ErrorSuccessNotifier.AddErrorMessage(ex.Message);
                    }
                    else
                    {
                        ErrorSuccessNotifier.AddErrorMessage(ex);
                    }
                }
            }
        }
 public ActionResult Edit(Message message)
 {
     if (ModelState.IsValid)
     {
         db.Entry(message).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(message);
 }