示例#1
0
        // GET: SMSMvc/Create
        public ActionResult Create(int? recipientId)
        {
            var model = new SMSCreateVM();
            model.MyContacts = new SelectList(CurrentUser.Contacts, "Id", "FullName", recipientId.GetValueOrDefault());

            return View(model);
        }
示例#2
0
        public ActionResult Create(SMSCreateVM sMS)
        {
            if (ModelState.IsValid)
            {
                SMS newMessage = new SMS { Recipient = db.Contacts.Find(sMS.SelectContactId) , Body = sMS.Body, User = CurrentUser};
                db.Contacts.FirstOrDefault(m => m.Id == newMessage.Recipient.Id).Messages.Add(newMessage);
                db.SaveChanges();
                Success($"SMS ready to be sent to {newMessage.Recipient.FullName}");
                return RedirectToAction("Index");
            }

            sMS.MyContacts = new SelectList(CurrentUser.Contacts, "Id", "FullName", sMS.SelectContactId);
            db.SaveChanges();
            return View(sMS);
        }