Пример #1
0
        public IActionResult New()
        {
            var model = new NewProtocolModel();

            model.Protocol = new DispatchProtocol();

            var priorites = _callsService.GetCallPrioritesForDepartment(DepartmentId);

            model.CallPriorities = new SelectList(priorites, "DepartmentCallPriorityId", "Name", priorites.FirstOrDefault(x => x.IsDefault));

            List <CallType> types = new List <CallType>();

            types.Add(new CallType {
                CallTypeId = 0, Type = "No Type"
            });
            types.AddRange(_callsService.GetCallTypesForDepartment(DepartmentId));
            model.CallTypes = new SelectList(types, "Type", "Type");

            model.TriggerTypes = model.TriggerTypesEnum.ToSelectList();

            return(View(model));
        }
Пример #2
0
        public async Task <IActionResult> New()
        {
            var model = new NewProtocolModel();

            model.Protocol = new DispatchProtocol();

            var priorites = await _callsService.GetActiveCallPrioritiesForDepartmentAsync(DepartmentId);

            model.CallPriorities = new SelectList(priorites, "DepartmentCallPriorityId", "Name", priorites.FirstOrDefault(x => x.IsDefault));

            List <CallType> types = new List <CallType>();

            types.Add(new CallType {
                CallTypeId = 0, Type = "No Type"
            });
            types.AddRange(await _callsService.GetCallTypesForDepartmentAsync(DepartmentId));
            model.CallTypes = new SelectList(types, "Type", "Type");

            model.TriggerTypes             = model.TriggerTypesEnum.ToSelectList();
            model.Protocol.CreatedByUserId = UserId;
            model.Protocol.UpdatedByUserId = UserId;

            return(View(model));
        }
Пример #3
0
        public async Task <IActionResult> New(NewProtocolModel model, IFormCollection form, ICollection <IFormFile> attachments)
        {
            if (attachments != null)
            {
                model.Protocol.Attachments = new Collection <DispatchProtocolAttachment>();
                foreach (var file in attachments)
                {
                    if (file != null && file.Length > 0)
                    {
                        var extenion = file.FileName.Substring(file.FileName.IndexOf(char.Parse(".")) + 1,
                                                               file.FileName.Length - file.FileName.IndexOf(char.Parse(".")) - 1);

                        if (!String.IsNullOrWhiteSpace(extenion))
                        {
                            extenion = extenion.ToLower();
                        }

                        if (extenion != "jpg" && extenion != "jpeg" && extenion != "png" && extenion != "gif" && extenion != "gif" &&
                            extenion != "pdf" && extenion != "doc" &&
                            extenion != "docx" && extenion != "ppt" && extenion != "pptx" && extenion != "pps" && extenion != "ppsx" &&
                            extenion != "odt" &&
                            extenion != "xls" && extenion != "xlsx" && extenion != "txt" && extenion != "mpg" && extenion != "avi" &&
                            extenion != "mpeg")
                        {
                            ModelState.AddModelError("fileToUpload", string.Format("File type ({0}) is not importable.", extenion));
                        }

                        if (file.Length > 30000000)
                        {
                            ModelState.AddModelError("fileToUpload", "Attachment is too large, must be smaller then 30MB.");
                        }

                        var attachment = new DispatchProtocolAttachment();
                        attachment.FileType = file.ContentType;
                        attachment.FileName = file.FileName;

                        var uploadedFile = new byte[file.OpenReadStream().Length];
                        file.OpenReadStream().Read(uploadedFile, 0, uploadedFile.Length);

                        attachment.Data = uploadedFile;
                        model.Protocol.Attachments.Add(attachment);
                    }
                }
            }

            model.Protocol.CreatedByUserId = UserId;
            model.Protocol.UpdatedByUserId = UserId;

            if (ModelState.IsValid)
            {
                List <int> triggers = (from object key in form.Keys
                                       where key.ToString().StartsWith("triggerType_")
                                       select int.Parse(key.ToString().Replace("triggerType_", ""))).ToList();

                if (triggers.Count > 0)
                {
                    model.Protocol.Triggers = new Collection <DispatchProtocolTrigger>();
                }

                model.Protocol.DepartmentId    = DepartmentId;
                model.Protocol.CreatedOn       = DateTime.UtcNow;
                model.Protocol.CreatedByUserId = UserId;
                model.Protocol.UpdatedOn       = DateTime.UtcNow;
                model.Protocol.UpdatedByUserId = UserId;
                model.Protocol.Code            = model.Protocol.Code.ToUpper();

                foreach (var i in triggers)
                {
                    if (form.ContainsKey("triggerType_" + i))
                    {
                        var triggerType         = int.Parse(form["triggerType_" + i]);
                        var triggerStartsOn     = form["triggerStartsOn_" + i];
                        var triggerEndsOn       = form["triggerEndsOn_" + i];
                        var triggerCallPriotity = int.Parse(form["triggerCallPriority_" + i]);
                        var triggerCallType     = form["triggerCallType_" + i];

                        var trigger = new DispatchProtocolTrigger();
                        trigger.Type = triggerType;

                        if (!String.IsNullOrWhiteSpace(triggerStartsOn))
                        {
                            trigger.StartsOn = DateTime.Parse(triggerStartsOn);
                        }

                        if (!String.IsNullOrWhiteSpace(triggerEndsOn))
                        {
                            trigger.EndsOn = DateTime.Parse(triggerEndsOn);
                        }

                        trigger.Priority = triggerType;
                        trigger.CallType = triggerCallType;

                        model.Protocol.Triggers.Add(trigger);
                    }
                }

                List <int> questions = (from object key in form.Keys where key.ToString().StartsWith("question_") select int.Parse(key.ToString().Replace("question_", ""))).ToList();

                if (questions.Count > 0)
                {
                    model.Protocol.Questions = new Collection <DispatchProtocolQuestion>();
                }

                foreach (var i in questions)
                {
                    if (form.ContainsKey("question_" + i))
                    {
                        var questionText = form["question_" + i];
                        var question     = new DispatchProtocolQuestion();
                        question.Question = questionText;

                        List <int> answers = (from object key in form.Keys where key.ToString().StartsWith("answerForQuestion_" + i + "_") select int.Parse(key.ToString().Replace("answerForQuestion_" + i + "_", ""))).ToList();

                        if (answers.Count > 0)
                        {
                            question.Answers = new Collection <DispatchProtocolQuestionAnswer>();
                        }

                        foreach (var answer in answers)
                        {
                            var trainingQuestionAnswer = new DispatchProtocolQuestionAnswer();
                            var answerForQuestion      = form["answerForQuestion_" + i + "_" + answer];

                            var weight = form["weightForAnswer_" + i + "_" + answer];
                            trainingQuestionAnswer.Answer = answerForQuestion;

                            if (!string.IsNullOrWhiteSpace(weight))
                            {
                                trainingQuestionAnswer.Weight = int.Parse(weight);
                            }

                            question.Answers.Add(trainingQuestionAnswer);
                        }

                        model.Protocol.Questions.Add(question);
                    }
                }


                await _protocolsService.SaveProtocolAsync(model.Protocol);

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }