示例#1
0
        public ActionResult PersonalInfo(int?id, int?contactPersonId)
        {
            if (contactPersonId.HasValue)
            {
                ViewBag.ContactPersonFrom = this.COVID19Entities.People.First(x => x.Personid == contactPersonId.Value);
            }

            var maritalStatusOptions = this.COVID19Entities.MaritalStatus.ToList().Select(x =>
                                                                                          new SelectListItem
            {
                Text  = x.MaritalStatus,
                Value = x.Id.ToString()
            }
                                                                                          ).ToList();

            ViewBag.maritalStatusOptions = maritalStatusOptions;

            var contactReasons = this.COVID19Entities.ContactReasons.ToList().Select(x => new SelectListItem
            {
                Text  = x.Reason,
                Value = x.Id.ToString()
            }).ToList();

            ViewBag.ContactReasons = contactReasons;

            if (id.HasValue)
            {
                var dbPerson = this.COVID19Entities.People.First(x => x.Personid == id.Value);
                var model    = new NewPersonDtoStep1
                {
                    PersonID         = id.Value,
                    Name             = dbPerson.Name,
                    SecondName       = dbPerson.SecondName,
                    LastName         = dbPerson.LastName,
                    DocumentNumber   = dbPerson.DocumentNumber,
                    Gender           = dbPerson.Gender,
                    BirrhtDate       = dbPerson.BirrhtDate,
                    MaritalSatatusID = dbPerson.MaritalSatatusID,
                    ContactPersonId  = contactPersonId
                };

                return(View(model));
            }
            else
            {
                var model = new NewPersonDtoStep1
                {
                    ContactPersonId = contactPersonId
                };
                return(View(model));
            }
        }
示例#2
0
        public ActionResult PersonalInfo(NewPersonDtoStep1 model)
        {
            if (!ModelState.IsValid)
            {
                if (model.ContactPersonId.HasValue)
                {
                    ViewBag.ContactPersonFrom = this.COVID19Entities.People.First(x => x.Personid == model.ContactPersonId.Value);
                }

                var maritalStatusOptions = this.COVID19Entities.MaritalStatus.ToList().Select(x =>
                                                                                              new SelectListItem
                {
                    Text  = x.MaritalStatus,
                    Value = x.Id.ToString()
                }
                                                                                              ).ToList();

                ViewBag.maritalStatusOptions = maritalStatusOptions;

                var contactReasons = this.COVID19Entities.ContactReasons.ToList().Select(x => new SelectListItem
                {
                    Text  = x.Reason,
                    Value = x.Id.ToString()
                }).ToList();
                ViewBag.ContactReasons = contactReasons;

                return(View(model));
            }

            Person dbPerson;

            if (model.PersonID == 0)
            {
                var existingPersonByDocumentNumber = this.COVID19Entities.People.FirstOrDefault(x => x.DocumentNumber == model.DocumentNumber);
                if (existingPersonByDocumentNumber != null)
                {
                    ModelState.AddModelError(string.Empty, "El documento ya está en uso");

                    var maritalStatusOptions = this.COVID19Entities.MaritalStatus.ToList().Select(x =>
                                                                                                  new SelectListItem
                    {
                        Text  = x.MaritalStatus,
                        Value = x.Id.ToString()
                    }
                                                                                                  ).ToList();

                    ViewBag.maritalStatusOptions = maritalStatusOptions;

                    var contactReasons = this.COVID19Entities.ContactReasons.ToList().Select(x => new SelectListItem
                    {
                        Text  = x.Reason,
                        Value = x.Id.ToString()
                    }).ToList();
                    ViewBag.ContactReasons = contactReasons;

                    return(View(model));
                }

                dbPerson = new Person
                {
                    Name             = model.Name,
                    SecondName       = model.SecondName,
                    LastName         = model.LastName,
                    DocumentTypeID   = -1,
                    DocumentNumber   = model.DocumentNumber,
                    Gender           = model.Gender,
                    BirrhtDate       = model.BirrhtDate,
                    MaritalSatatusID = model.MaritalSatatusID,
                    EffectDate       = DateTime.Now,
                    Adress           = new Adress
                    {
                    },
                    Patients = new List <Patient>()
                    {
                        new Patient {
                            EffectDate = DateTime.Now
                        }
                    }
                };

                this.COVID19Entities.People.Add(dbPerson);
                this.COVID19Entities.SaveChanges();

                // CREACIÓN
                var dbPatientHistory = new PatientHistory
                {
                    ActionID    = 5,
                    EffectDate  = DateTime.Now,
                    Datetime    = DateTime.Now,
                    Observation = User.Identity.Name + " creó el nuevo registro con éxito",
                    PatientID   = dbPerson.Patients.First().PatientID
                };

                this.COVID19Entities.PatientHistories.Add(dbPatientHistory);
                this.COVID19Entities.SaveChanges();

                if (model.ContactPersonId.HasValue)
                {
                    // FEDE! TE CEDO EL PODER!

                    var contactDbPerson = this.COVID19Entities.People.First(x => x.Personid == model.ContactPersonId);

                    var dbContact = new Contact
                    {
                        PatientID       = dbPerson.Patients.First().PatientID, //dbPerson.Patients.First().PatientID,
                        ContactPersonId = model.ContactPersonId,
                        EffectDate      = DateTime.Now,
                        Observations    = model.ContactObservations,
                        ContactReasonId = model.ContactReasonId
                    };

                    this.COVID19Entities.Contacts.Add(dbContact);
                    this.COVID19Entities.SaveChanges();
                }
            }
            else
            {
                // EDICIÓN
                dbPerson = this.COVID19Entities.People.First(x => x.Personid == model.PersonID);

                dbPerson.Name             = model.Name;
                dbPerson.SecondName       = model.SecondName;
                dbPerson.LastName         = model.LastName;
                dbPerson.DocumentTypeID   = -1;
                dbPerson.DocumentNumber   = model.DocumentNumber;
                dbPerson.Gender           = model.Gender;
                dbPerson.BirrhtDate       = model.BirrhtDate;
                dbPerson.MaritalSatatusID = model.MaritalSatatusID;
                dbPerson.EffectDate       = DateTime.Now;

                this.COVID19Entities.SaveChanges();
            }

            return(RedirectToAction("Address", "Person", new { id = dbPerson.Personid }));
        }