public ActionResult Create(long arcid = 0)
        {
            ViewBag.Devices = new SelectList(db.Devices, "ID", "DeviceCode");

            if (arcid == 0)
            {
                Message message = new Message()
                {
                    MessageType = 1,
                    Status = 1,
                    ValidFrom = new DateTime(DateTime.Now.Year, 1, 1),
                    ValidTo = new DateTime(DateTime.Now.Year + 1, 12, 31)
                };

                return View(message);
            }
            else
            {
                Message msg = null;
                MessageArchive arc = db.MessageArchives.Find(arcid);
                if (arc != null)
                {
                    msg = new Message()
                    {
                        DeviceID = arc.DeviceID,
                        ExtDate1 = arc.ExtDate1,
                        ExtDate2 = arc.ExtDate2,
                        ExtDate3 = arc.ExtDate3,
                        ExtString1 = arc.ExtString1,
                        ExtString2 = arc.ExtString2,
                        ExtString3 = arc.ExtString3,
                        ExtDec1 = arc.ExtDec1,
                        ExtDec2 = arc.ExtDec2,
                        ExtDec3 = arc.ExtDec3,
                        MessageContent = arc.MessageContent,
                        MessageType = arc.MessageType,
                        Remarks = arc.Remarks,
                        Status = arc.Status,
                        ValidFrom = arc.ValidFrom,
                        ValidTo = arc.ValidTo
                    };
                }
                return View(msg);
            }
        }
 public ActionResult Edit(Message message)
 {
     if (ModelState.IsValid)
     {
         db.Entry(message).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(message);
 }
 private void SendMessage(string msg, List<Device> devices, long? index, int? indexRange)
 {
     foreach (Device device in devices)
     {
         Message message = new Message()
         {
             MessageContent = msg,
             DeviceID = device.ID,
             MessageType = 1,
             Status = 1,
             ValidFrom = new DateTime(DateTime.Now.Year, 1, 1),
             ValidTo = new DateTime(DateTime.Now.Year + 1, 12, 31),
             RequestIndex = index,
             RequestIndexRange = indexRange
         };
         db.Messages.Add(message);
     }
 }
        public ActionResult Create(Message message)
        {
            if (ModelState.IsValid)
            {
                db.Messages.Add(message);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.Devices = new SelectList(db.Devices, "ID", "DeviceID");

            return View(message);
        }