Exemple #1
0
        public ActionResult Cancel(EmergencyModel emergencyModel)
        {
            EmergencyHistoryModel emergencyHistoryModel = new EmergencyHistoryModel()
            {
                Date            = DateTime.Now,
                EmergencyId     = emergencyModel.Id,
                EmployeeGuid    = emergencyModel.EmployeeGuid,
                EmergencyStatus = EmergencyStatus.Canceled,
                Description     = emergencyModel.Description
            };
            var resultEmergency = _emergencyRest.Find(new EmergencyFilter {
                Id = emergencyModel.Id
            });

            if (!resultEmergency.Success)
            {
                ViewBag.Error = resultEmergency.Messages;
                LoadBag();
                return(View("Index", emergencyModel));
            }
            resultEmergency.Model.EmergencyStatus = EmergencyStatus.Canceled;
            emergencyHistoryModel.EmergencyModel  = resultEmergency.Model;
            var result = _emergencyHistoryRest.Register(emergencyHistoryModel);

            if (!result.Success)
            {
                ViewBag.Error = result.Messages;
                LoadBag();
                return(View("Index", emergencyModel));
            }

            LoadBag();
            return(View("Index", new EmergencyModel()));
        }
Exemple #2
0
 public int CreateEmergency(EmergencyModel newEmergency)
 {
     using (System.Data.IDbConnection connection = new System.Data.SqlClient.SqlConnection(configName))
     {
         var qry = "INSERT INTO ClientEmergency (EmergencyDate,ClientID,EmergencyLon,EmergencyLat,EmergencyAddress,EmergencyStatusID)";
         qry += " VALUES (GETDATE()," + newEmergency.ClientID + "," + newEmergency.EmergencyLon.ToString().Replace(",", ".") + "," + newEmergency.EmergencyLat.ToString().Replace(",", ".") + ",'" + newEmergency.EmergencyAddress + "',1)";
         qry += " Select @@IDENTITY as NewID";
         var output = connection.Query <int>(qry);
         return(output.First());
     }
 }
Exemple #3
0
 //Metodo de insercion de emergencias a firebase
 public async Task AddEmergency(EmergencyModel emergency)
 {
     await firebase
     .Child("Emergency")
     .PostAsync(new EmergencyModel()
     {
         DateTime  = emergency.DateTime,
         Latitude  = emergency.Latitude,
         Longitude = emergency.Longitude,
         UserId    = emergency.UserId
     });
 }
 public ActionResult Save(EmergencyModel emergencyModel)
 {
     if (!ModelState.IsValid)
     {
         var viewModel = new EmergencyModel();
         viewModel = emergencyModel;
         return(View("Create", viewModel));
     }
     _context.Emergency.Add(emergencyModel);
     _context.SaveChanges();
     return(RedirectToAction("Search", "Emergency"));
 }
Exemple #5
0
        public IActionResult Register(EmergencyModel emergencyModel)
        {
            if (emergencyModel.Cancel)
            {
                return(RedirectToAction("Cancel", emergencyModel));
            }
            emergencyModel.EmployeeGuid = _userService.GetCurrentUser().EmployeeGuid;


            LoadBag();
            return(View("Index", new EmergencyModel()));
        }
Exemple #6
0
        // GET: Emergency/Details/5
        public int SaveNewEmergency(int ClientID, float Lat, float Lng, string Address)
        {
            DAL.DAL_Emergency dl     = new DAL.DAL_Emergency();
            EmergencyModel    xModel = new EmergencyModel();

            xModel.ClientID         = ClientID;
            xModel.EmergencyLat     = Lat;
            xModel.EmergencyLon     = Lng;
            xModel.EmergencyAddress = Address;
            int EmID = dl.CreateEmergency(xModel);

            return(EmID);
        }
Exemple #7
0
        public ActionResult Cancel(EmergencyModel emergencyModel)
        {
            var user = _userService.GetCurrentUser();

            var resultFind = _requiredVehicleRest.Find(new RequiredVehicleFilter {
                Id = emergencyModel.RequiredVehicleId
            });

            if (!resultFind.Success)
            {
                ViewBag.Error = resultFind.Messages;
                LoadBag();
                return(View("Index", emergencyModel));
            }

            EmergencyHistoryModel emergencyHistoryModel = new EmergencyHistoryModel()
            {
                Date            = DateTime.Now,
                EmergencyId     = emergencyModel.Id,
                EmployeeGuid    = user.EmployeeGuid,
                EmergencyStatus = emergencyModel.EmergencyStatus,
                Description     = emergencyModel.Description + " - Cancelamento de veículo " + resultFind.Model.VehicleType.GetEnumDescription()
            };

            MedicalDecisionHistoryModel medicalDecision = new MedicalDecisionHistoryModel()
            {
                Date         = DateTime.Now,
                EmployeeGuid = user.EmployeeGuid,
                EmployeeName = user.EmployeeName,
                CodeColor    = resultFind.Model.CodeColor,
                EmergencyId  = emergencyModel.Id,
                Description  = emergencyModel.Description + " - Cancelamento de veículo " + resultFind.Model.VehicleType
            };


            resultFind.Model.EmergencyHistoryModel       = emergencyHistoryModel;
            resultFind.Model.MedicalDecisionHistoryModel = medicalDecision;
            resultFind.Model.Status = VehicleRequiredStatus.Canceled;
            var result = _requiredVehicleRest.Update(resultFind.Model);

            if (!result.Success)
            {
                ViewBag.Error = result.Messages;
                LoadBag();
                return(View("Index", emergencyModel));
            }

            LoadBag();
            return(View("Index", new EmergencyModel()));
        }
        public IActionResult RegisterMedicalEvaluation(EmergencyModel emergencyModel)
        {
            var resultEmergency = _emergencyRest.Find(new EmergencyFilter {
                Id = emergencyModel.Id
            });

            if (!resultEmergency.Success)
            {
                ViewBag.Error = resultEmergency.Messages;
                LoadBag();
                return(View("Index", emergencyModel));
            }
            List <MedicalEvaluationModel> evaluations = new List <MedicalEvaluationModel>();
            var user = _userService.GetCurrentUser();

            foreach (var patient in emergencyModel.PatientModels)
            {
                MedicalEvaluationModel medicalEvaluationModel = new MedicalEvaluationModel
                {
                    EmergencyId  = emergencyModel.Id,
                    EmployeeGuid = user.EmployeeGuid,
                    EmployeeName = user.EmployeeName,
                    Evaluation   = patient.Description,
                    Date         = DateTime.Now,
                    PatientId    = patient.Id,
                    PatientModel = patient,
                };
                patient.EmergencyId = emergencyModel.Id;
                evaluations.Add(medicalEvaluationModel);
            }

            var result = _medicalEvaluationRest.RegisterEvaluations(evaluations);

            if (!result.Success)
            {
                ViewBag.Error = result.Messages;
                LoadBag();
                return(View("Index", resultEmergency.Model));
            }
            resultEmergency = _emergencyRest.Find(new EmergencyFilter {
                Id = emergencyModel.Id
            });
            LoadBag();
            return(View("Index", resultEmergency.Model));
        }
Exemple #9
0
        public IActionResult Register(EmergencyModel emergencyModel)
        {
            emergencyModel.EmployeeGuid = _userService.GetCurrentUser().EmployeeGuid;
            if (emergencyModel.Cancel)
            {
                return(RedirectToAction("Cancel", emergencyModel));
            }

            if (string.IsNullOrWhiteSpace(emergencyModel.RequesterPhone))
            {
                ModelState.AddModelError("RequesterPhone", "Favor preencher telefone");
                LoadBag();
                return(View("index", new EmergencyModel()));
            }
            if ((emergencyModel?.Id ?? 0) == 0)
            {//register
                var requesterResult = _requesterService.Find(new RequesterFilter {
                    Telephone = emergencyModel.RequesterPhone
                });
                if (!requesterResult.Success)
                {
                    ViewBag.Error = new List <string>()
                    {
                        requesterResult?.Messages?.FirstOrDefault() ?? "Ocorreu um erro, favor tente novamente."
                    };
                    LoadBag();
                    return(View("Index", new EmergencyModel()));
                }

                emergencyModel.AddressModel = requesterResult?.Model?.AddressModel;
                if (emergencyModel.AddressModel != null)
                {
                    emergencyModel.AddressModel.Id = 0;
                }

                emergencyModel.EmergencyStatus = EmergencyStatus.Opened;
                emergencyModel.RequesterName   = requesterResult?.Model?.Name ?? "";
                emergencyModel.Name            = "";
                emergencyModel.Date            = DateTime.Now;

                var emergencyResult = _emergencyRest.SimpleRegister(emergencyModel);
                if (!emergencyResult.Success)
                {
                    ViewBag.Error = new List <string> {
                        emergencyResult?.Messages?.FirstOrDefault() ?? "Ocorreu um erro, favor tente novamente."
                    };
                    LoadBag();
                    return(View("Index", emergencyModel));
                }
                emergencyModel.Id = emergencyResult.Id;

                LoadBag();
                return(View("Index", emergencyModel));
            }
            else
            {//update
                var requesterResultFind = _requesterService.Find(new RequesterFilter {
                    Telephone = emergencyModel.RequesterPhone
                });
                if (!requesterResultFind.Success)
                {
                    ViewBag.Error = new List <string> {
                        requesterResultFind?.Messages?.FirstOrDefault() ?? "Ocorreu um erro, favor tente novamente."
                    };
                    LoadBag();
                    return(View("Index", emergencyModel));
                }
                if ((requesterResultFind?.Model?.Id ?? 0) == 0)
                {
                    var requesterResult = _requesterService.Register(new RequesterModel
                    {
                        AddressModel = emergencyModel.AddressModel,
                        Name         = emergencyModel.RequesterName,
                        Telephone    = emergencyModel.RequesterPhone
                    });
                    if (!requesterResult.Success)
                    {
                        ViewBag.Error = requesterResult.Messages;
                        LoadBag();
                        return(View("Index", emergencyModel));
                    }
                }
                else
                {
                    requesterResultFind.Model.AddressModel = emergencyModel.AddressModel;
                    requesterResultFind.Model.Name         = emergencyModel.RequesterName;
                    requesterResultFind.Model.Telephone    = emergencyModel.RequesterPhone;
                    var requesterResult = _requesterService.Update(requesterResultFind.Model);
                    if (!requesterResult.Success)
                    {
                        ViewBag.Error = requesterResult.Messages;
                        LoadBag();
                        return(View("Index", emergencyModel));
                    }
                }
                if (emergencyModel.EmergencyStatus == EmergencyStatus.Opened)
                {
                    emergencyModel.EmergencyStatus = EmergencyStatus.InEvaluation;
                }

                var emergencyResult = _emergencyRest.Update(emergencyModel);
                if (!emergencyResult.Success)
                {
                    ViewBag.Error = emergencyResult.Messages;
                    LoadBag();
                    return(View("Index", emergencyModel));
                }

                LoadBag();
                return(View("Index", new EmergencyModel()));
            }
        }