コード例 #1
0
        //
        // GET: /PhoneCall/Create
        public ActionResult Create()
        {
            PhoneCallViewModel vm = new PhoneCallViewModel();
            vm.Date = DateTime.Now.Date;

            //I know I am doing this inefficiently. Don't need a list of entity models in VM
            //vm.Plaintiffs = db.Plaintiffs.OrderBy(p => p.LastName);
            //vm.Organizations = db.Organizations.OrderBy(o => o.Name);
            //vm.Contacts = db.Contacts.OrderBy(c => c.LastName);

            return View(vm);
        }
コード例 #2
0
        public string Create(PhoneCallViewModel phoneCall)
        {
            if (ModelState.IsValid)
            {
                var possibleContacts = from item in db.Contacts
                                       where item.FirstName.ToLower().StartsWith(phoneCall.ContactFirstName) ||
                                       item.LastName.ToLower().StartsWith(phoneCall.ContactLastName)
                                       orderby item.LastName
                                       select new { item.Id, item.FirstName, item.LastName };

                foreach (var item in possibleContacts)
                {
                    PhoneCallViewModel.ContactMatch cMatch = new PhoneCallViewModel.ContactMatch();
                    cMatch.ContactId = item.Id;
                    cMatch.FullName = item.FirstName + " " + item.LastName;
                    phoneCall.ContactMatches.Add(cMatch);
                }

                var possiblePlaintiffs = from item in db.Plaintiffs
                                         where item.FirstName.ToLower().StartsWith(phoneCall.PlaintiffFirstName) ||
                                         item.LastName.ToLower().StartsWith(phoneCall.PlaintiffLastName)
                                         orderby item.LastName
                                         select new { item.Id, item.FirstName, item.LastName };

                foreach (var item in possiblePlaintiffs)
                {
                    PhoneCallViewModel.PlaintiffMatch pMatch = new PhoneCallViewModel.PlaintiffMatch();
                    pMatch.PlaintiffId = item.Id;
                    pMatch.FullName = item.FirstName + " " + item.LastName;
                    phoneCall.PlaintiffMatches.Add(pMatch);
                }
                var result = JsonConvert.SerializeObject(phoneCall);

                //   There may be a better way to do this...
                //I am storing result of form in private PhoneCall variable defined at start of controller.
                phoneCallFinal.Message = phoneCall.Message;
                phoneCallFinal.Date = phoneCall.Date;

                return result;
            }

            return "There was a problem";
        }
コード例 #3
0
 public ActionResult AddPhoneCall(PhoneCallViewModel vm)
 {
     return null;
 }