Exemplo n.º 1
0
 public void CreateMessage(Message data)
 {
     data.Create_Time = DateTime.Now;
     db.Message.Add(data);
     db.SaveChanges();
     db.Dispose();
 }
Exemplo n.º 2
0
        public ActionResult Create([Bind(Include = "Id,MessageText,Datestamp")] Message message)
        {
            if (ModelState.IsValid)
            {
                db.Messages.Add(message);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(message));
        }
Exemplo n.º 3
0
        public static bool Add(Message message)
        {
            MessageEntities context = new MessageEntities();

            context.Messages.AddObject(message);
            return(context.SaveChanges() > 0 ? true : false);
        }
Exemplo n.º 4
0
        public static bool Update(Message message)
        {
            MessageEntities context = new MessageEntities();

            context.Messages.Attach(message);
            context.ObjectStateManager.ChangeObjectState(message, EntityState.Modified);
            return(context.SaveChanges() > 0 ? true : false);
        }
Exemplo n.º 5
0
        public static bool Delete(int id)
        {
            MessageEntities context = new MessageEntities();
            Message         message = new Message();

            message.id = id;
            context.Messages.Attach(message);
            context.ObjectStateManager.ChangeObjectState(message, EntityState.Deleted);
            return(context.SaveChanges() > 0 ? true : false);
        }
Exemplo n.º 6
0
        public bool AddNewMessage(string text)
        {
            using (MessageEntities MessageEntity = new MessageEntities())
            {
                try
                {
                    Messages newMessage = new Messages(text);
                    MessageEntity.Messages.Add(newMessage);
                    MessageEntity.SaveChanges();

                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
Exemplo n.º 7
0
        public ActionResult Message(string MsgName, string MsgEmail, string MsgPhone, string MsgSub, string MsgContent)
        {
            Message message = new Message();

            message.MsgName    = MsgName;
            message.MsgEmail   = MsgEmail;
            message.MsgPhone   = MsgPhone;
            message.MsgSub     = MsgSub;
            message.MsgContent = MsgContent;

            if (ModelState.IsValid)
            {
                db.Messages.Add(message);
                db.SaveChanges();
                ViewBag.feedBack = "Your message has been sent";
                ModelState.Clear();
                return(View("Contact"));
            }
            else
            {
                ViewBag.feedBack = "There was an error sending your message, please try again";
                return(View("Contact"));
            }
        }