Esempio n. 1
0
        public ActionResult Send()
        {
            SendRecallModel m = new SendRecallModel()
            {
                PatientCodesCsv = Request.Form["PatientCodesCsv"],
                TemplateBody    = Request.Form["TemplateBody"]
            };



            List <MessageTemplate> recallTemplates;

            using (var service = new MessageTemplateService())
            {
                recallTemplates = service.GetWhere(MessageTemplateService.PharmacyCodeCol == User.Pharmacy.Code & MessageTemplateService.TypeCol == MessageTemplateType.RECALL);

                foreach (MessageTemplate t in recallTemplates)
                {
                    t.Content = m.TemplateBody;
                    service.Update(t);
                }
            }

            string[]     codes         = m.PatientCodesCsv.Split(',');
            List <Event> eventsCreated = new List <Event>();

            foreach (string code in codes)
            {
                Patient p = null;
                using (var service = new PatientService())
                {
                    p = service.Get(code);
                }
                if (p != null)
                {
                    Event e = new Event
                    {
                        Status  = EventStatus.ToSend,
                        Patient = p,
                        Type    = EventType.RECALL
                    };
                    using (var service = new EventService())
                    {
                        service.Create(e);
                    }
                    eventsCreated.Add(e);
                    EventRecall er = new EventRecall
                    {
                        Event = e
                    };
                    using (var service = new EventRecallService())
                    {
                        service.Create(er);
                    }
                }
            }
            EventProcessingService.SendEvents(eventsCreated, recallTemplates);

            return(RedirectToAction("SendConfirmation", new { numSent = eventsCreated.Count }));
        }