Exemple #1
0
        private void PopulateLogViewModel(NewLogView model)
        {
            model.Department     = _departmentsService.GetDepartmentByUserId(UserId);
            model.User           = _usersService.GetUserById(UserId);
            model.Types          = model.LogType.ToSelectList();
            model.CallPriorities = model.CallPriority.ToSelectList();
            model.Users.Add(String.Empty, "Not Applicable");
            model.SetUsers(_departmentsService.GetAllUsersForDepartment(DepartmentId));
            var groups = new List <DepartmentGroup>();

            groups.Add(new DepartmentGroup
            {
                Name = "Not Applicable"
            });
            groups.AddRange(_departmentGroupsService.GetAllStationGroupsForDepartment(DepartmentId));
            model.Stations = groups;

            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");
        }
Exemple #2
0
        public IActionResult NewLog()
        {
            var model = new NewLogView();

            PopulateLogViewModel(model);
            model.Log = new Log();

            return(View(model));
        }
Exemple #3
0
        public async Task <IActionResult> NewLog()
        {
            var model = new NewLogView();

            await PopulateLogViewModel(model);

            model.Log = new Log();

            return(View(model));
        }
Exemple #4
0
        public IActionResult NewLog(NewLogView model, IFormCollection form, ICollection <IFormFile> files)
        {
            PopulateLogViewModel(model);

            if (model.LogType == LogTypes.Work && String.IsNullOrWhiteSpace(form["nonUnitPersonnel"]))
            {
                model.ErrorMessage = "You need to specify at least 1 person to be part of the work log.";
                return(View(model));
            }

            try
            {
                try
                {
                    if (files != null && files.Any())
                    {
                        foreach (var file in files)
                        {
                            if (file != null && !String.IsNullOrWhiteSpace(file.FileName))
                            {
                                string extension = Path.GetExtension(file.FileName);

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

                                if (extension != ".jpg" && extension != ".jpeg" && extension != ".png" && extension != ".gif" && extension != ".pdf" &&
                                    extension != ".doc" && extension != ".docx" && extension != ".ppt" && extension != ".pptx" && extension != ".pps" &&
                                    extension != ".ppsx" && extension != ".odt" && extension != ".xls" && extension != ".xlsx" && extension != ".txt" && extension != ".rtf")
                                {
                                    model.ErrorMessage = string.Format("File type ({0}) is not importable.", extension);
                                }

                                if (file.Length > 10000000)
                                {
                                    model.ErrorMessage = "Document is too large, must be smaller then 10MB.";
                                }
                            }
                        }
                    }
                }
                catch { }

                if (!String.IsNullOrWhiteSpace(model.ErrorMessage))
                {
                    return(View(model));
                }

                // Get all unit blocks in the report
                List <int> unitsInReport = (from object key in form.Keys where key.ToString().StartsWith("unit_personnel_") select int.Parse(key.ToString().Replace("unit_personnel_", ""))).ToList();

                model.Log.LoggedByUserId = UserId;
                model.Log.DepartmentId   = model.Department.DepartmentId;
                model.Log.Narrative      = System.Net.WebUtility.HtmlDecode(model.Log.Narrative);
                model.Log.Cause          = System.Net.WebUtility.HtmlDecode(model.Log.Cause);
                model.Log.InitialReport  = System.Net.WebUtility.HtmlDecode(model.Log.InitialReport);
                model.Log.LogType        = (int)model.LogType;

                if (model.Log.StationGroupId == 0)
                {
                    model.Log.StationGroupId = null;
                }

                model.Log.Units = new Collection <LogUnit>();
                model.Log.Users = new Collection <LogUser>();

                if (String.IsNullOrWhiteSpace(model.Log.InvestigatedByUserId))
                {
                    model.Log.InvestigatedByUserId = null;
                }

                if (model.Log.StationGroupId.HasValue && model.Log.StationGroupId.Value == 0)
                {
                    model.Log.StationGroupId = null;
                }

                if (model.LogType == LogTypes.Run)
                {
                    if (model.CallId == 0)
                    {
                        model.Call.DepartmentId    = DepartmentId;
                        model.Call.ReportingUserId = UserId;
                        model.Call.Priority        = (int)model.CallPriority;

                        if (model.Call.Type == "No Type")
                        {
                            model.Call.Type = null;
                        }

                        model.Call          = _callsService.SaveCall(model.Call);
                        model.Log.CallId    = model.Call.CallId;
                        model.Log.StartedOn = model.Call.LoggedOn;
                    }
                    else
                    {
                        var call = _callsService.GetCallById(model.CallId);
                        call.Priority     = (int)model.CallPriority;
                        call.NatureOfCall = model.Call.NatureOfCall;
                        call.Address      = model.Call.Address;
                        call.LoggedOn     = model.Call.LoggedOn;
                        call.Name         = model.Call.Name;

                        model.Call       = _callsService.SaveCall(call);
                        model.Log.CallId = model.Call.CallId;
                    }
                }

                if (model.LogType == LogTypes.Work)
                {
                    var startedOn = form["Log.StartedOn"];
                    var endedOn   = form["Log.EndedOn"];

                    if (!String.IsNullOrWhiteSpace(startedOn))
                    {
                        model.Log.StartedOn = DateTime.Parse(startedOn);
                    }

                    if (!String.IsNullOrWhiteSpace(endedOn))
                    {
                        model.Log.EndedOn = DateTime.Parse(endedOn);
                    }
                }

                if (model.LogType == LogTypes.Meeting)
                {
                    var startedOn = form["Log.StartedOn"];
                    var endedOn   = form["Log.EndedOn"];

                    if (!String.IsNullOrWhiteSpace(startedOn))
                    {
                        model.Log.StartedOn = DateTime.Parse(startedOn);
                    }

                    if (!String.IsNullOrWhiteSpace(endedOn))
                    {
                        model.Log.EndedOn = DateTime.Parse(endedOn);
                    }
                }

                if (model.LogType == LogTypes.Coroner)
                {
                    var startedOn          = form["coronerDate"];
                    var caseNumber         = form["caseNumber"];
                    var coronerInstructors = form["coronerInstructors"];
                    var coronerDestination = form["coronerDestination"];
                    var coronerOthers      = form["coronerOthers"];

                    if (!String.IsNullOrWhiteSpace(startedOn))
                    {
                        model.Log.StartedOn = DateTime.Parse(startedOn);
                    }

                    if (!String.IsNullOrWhiteSpace(caseNumber))
                    {
                        model.Log.ExternalId = caseNumber;
                    }

                    if (!String.IsNullOrWhiteSpace(coronerInstructors))
                    {
                        model.Log.Instructors = coronerInstructors;
                    }

                    if (!String.IsNullOrWhiteSpace(coronerDestination))
                    {
                        model.Log.Location = coronerDestination;
                    }

                    if (!String.IsNullOrWhiteSpace(coronerOthers))
                    {
                        model.Log.OtherPersonnel = coronerOthers;
                    }
                }

                foreach (var i in unitsInReport)
                {
                    var unit = new LogUnit();
                    unit.UnitId = i;

                    if (!string.IsNullOrWhiteSpace(form["unit_dispatchtime_" + i]))
                    {
                        unit.Dispatched = DateTime.Parse(form["unit_dispatchtime_" + i]);
                    }

                    if (!string.IsNullOrWhiteSpace(form["unit_enroutetime_" + i]))
                    {
                        unit.Enroute = DateTime.Parse(form["unit_enroutetime_" + i]);
                    }

                    if (!string.IsNullOrWhiteSpace(form["unit_onscenetime_" + i]))
                    {
                        unit.OnScene = DateTime.Parse(form["unit_onscenetime_" + i]);
                    }

                    if (!string.IsNullOrWhiteSpace(form["unit_releasedtime_" + i]))
                    {
                        unit.Released = DateTime.Parse(form["unit_releasedtime_" + i]);
                    }

                    if (!string.IsNullOrWhiteSpace(form["unit_inquarterstime_" + i]))
                    {
                        unit.InQuarters = DateTime.Parse(form["unit_inquarterstime_" + i]);
                    }

                    model.Log.Units.Add(unit);

                    if (!string.IsNullOrWhiteSpace(form["unit_personnel_" + i]))
                    {
                        var personnelIds = form["unit_personnel_" + i].ToString().Split(char.Parse(","));

                        foreach (var personnelId in personnelIds)
                        {
                            var logUser = new LogUser();
                            logUser.UserId = personnelId;
                            logUser.UnitId = i;

                            model.Log.Users.Add(logUser);
                        }
                    }
                }

                if (!string.IsNullOrWhiteSpace(form["nonUnitPersonnel"]))
                {
                    var personnelIds = form["nonUnitPersonnel"].ToString().Split(char.Parse(","));

                    foreach (var personnelId in personnelIds)
                    {
                        var logUser = new LogUser();
                        logUser.UserId = personnelId;

                        model.Log.Users.Add(logUser);
                    }
                }

                var savedLog = _workLogsService.SaveLog(model.Log);

                try
                {
                    if (files != null)
                    {
                        foreach (var file in files)
                        {
                            if (file != null && file.Length > 0)
                            {
                                LogAttachment attachment = new LogAttachment();
                                attachment.LogId    = savedLog.LogId;
                                attachment.Type     = file.ContentType;
                                attachment.FileName = file.FileName;

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

                                attachment.Data      = uploadedFile;
                                attachment.UserId    = UserId;
                                attachment.Timestamp = DateTime.UtcNow;

                                _workLogsService.SaveLogAttachment(attachment);
                            }
                        }
                    }
                }
                catch { }

                _eventAggregator.SendMessage <LogAddedEvent>(new LogAddedEvent()
                {
                    DepartmentId = DepartmentId, Log = model.Log
                });
            }
            catch (Exception ex)
            {
                Logging.LogException(ex);

                model.ErrorMessage = "We encountered an error trying to save your log. Please check your form to ensure it's properly filled out and try again.";
                return(View(model));
            }

            return(RedirectToAction("Index"));
        }