public ActionResult Edit(IntakeRelationItem intakeRelationItem, FormCollection Formssss) { foreach (var key in Formssss.AllKeys) { var add = Formssss.Get(key); } var currentUser = (User)Session["CurrentUser"]; var userName = string.Empty; if (currentUser != null) { userName = currentUser.User_Name; } var personModel = new PersonModel(); var personItem = new Person(); var dateCreated = DateTime.Now; const string createdBy = "jhendrikse"; var dateLastModified = DateTime.Now; const string modifiedBy = "jhendrikse"; const bool isActive = true; const bool isDeleted = false; // Determine if a new Person has been added, or if an existing Person's details must be edited. if (intakeRelationItem.CreatePerson.Person.Person_Id == -1) { var newPersonDetail = intakeRelationItem.CreatePerson.Person; var PersonDisability = personModel.CreatePersonDisability(intakeRelationItem.Person_Id, intakeRelationItem.SelectedDisabilityId, userName); var physicalAddress = intakeRelationItem.CreatePerson.PhysicalAddress; var postalAddress = intakeRelationItem.CreatePerson.PostalAddress; // Create New Person personItem = personModel.CreatePerson(newPersonDetail.First_Name, newPersonDetail.Last_Name, newPersonDetail.Known_As, newPersonDetail.Identification_Type_Id, newPersonDetail.Identification_Number, false, null, newPersonDetail.Date_Of_Birth, newPersonDetail.Age, newPersonDetail.Is_Estimated_Age, newPersonDetail.Sexual_Orientation_Id, newPersonDetail.Language_Id, newPersonDetail.Gender_Id, newPersonDetail.Marital_Status_Id, newPersonDetail.Religion_Id, newPersonDetail.Preferred_Contact_Type_Id, newPersonDetail.Phone_Number, newPersonDetail.Mobile_Phone_Number, newPersonDetail.Email_Address, newPersonDetail.Population_Group_Id, newPersonDetail.Nationality_Id, newPersonDetail.Disability_Type_Id, newPersonDetail.Citizenship_Id, dateCreated, createdBy, isActive, isDeleted); if (personItem != null) { personModel.AddAddress(personItem.Person_Id, (int)AddressTypeEnum.PhysicalAddress, physicalAddress.Address_Line_1, physicalAddress.Address_Line_2, physicalAddress.Town_Id, physicalAddress.Postal_Code); personModel.AddAddress(personItem.Person_Id, (int)AddressTypeEnum.PostalAddress, postalAddress.Address_Line_1, postalAddress.Address_Line_2, postalAddress.Town_Id, postalAddress.Postal_Code); } } else { var editPersonDetail = intakeRelationItem.CreatePerson.Person; // Edit Person personItem = personModel.EditPerson(editPersonDetail.Person_Id, editPersonDetail.First_Name, editPersonDetail.Last_Name, editPersonDetail.Known_As, editPersonDetail.Identification_Type_Id, editPersonDetail.Identification_Number, editPersonDetail.Date_Of_Birth, editPersonDetail.Age, editPersonDetail.Is_Estimated_Age, editPersonDetail.Sexual_Orientation_Id, editPersonDetail.Language_Id, editPersonDetail.Gender_Id, editPersonDetail.Marital_Status_Id, editPersonDetail.Religion_Id, editPersonDetail.Preferred_Contact_Type_Id, editPersonDetail.Phone_Number, editPersonDetail.Mobile_Phone_Number, editPersonDetail.Email_Address, editPersonDetail.Population_Group_Id, editPersonDetail.Nationality_Id, editPersonDetail.Disability_Type_Id, editPersonDetail.Citizenship_Id, dateLastModified, modifiedBy, isActive, isDeleted); int Pid = editPersonDetail.Person_Id; //List<int> DIDS = editPersonDetail.SelectedDisabilityId; string usre = userName; } var status = "OK"; var message = "The education details have been successfully added"; if (personItem != null) { switch (intakeRelationItem.Relation_Type_Id) { case (int)RelationTypeEnum.AdoptiveParents: var clientAdoptionModel = new ClientAdoptiveParentModel(); var newAdoptiveParent = clientAdoptionModel.EditClientAdoptiveParent(intakeRelationItem.Item_Id, personItem.Person_Id, intakeRelationItem.IsDeceased, string.IsNullOrEmpty(intakeRelationItem.DateDeceased) ? (DateTime?)null : DateTime.Parse(intakeRelationItem.DateDeceased), dateLastModified, modifiedBy, isActive, isDeleted); if (newAdoptiveParent == null) { status = "Error"; message = "A technical error has occurred! Please try again later"; } break; case (int)RelationTypeEnum.BiologicalParents: var clientBiologicalModel = new ClientBiologicalParentModel(); var newBiologicalParent = clientBiologicalModel.EditClientBiologicalParent(intakeRelationItem.Item_Id, personItem.Person_Id, intakeRelationItem.IsDeceased, string.IsNullOrEmpty(intakeRelationItem.DateDeceased) ? (DateTime?)null : DateTime.Parse(intakeRelationItem.DateDeceased), dateCreated, createdBy, isActive, isDeleted); if (newBiologicalParent == null) { status = "Error"; message = "A technical error has occurred! Please try again later"; } break; case (int)RelationTypeEnum.Caregivers: var clientCaregiverModel = new ClientCareGiverModel(); var newClientCareverModel = clientCaregiverModel.EditClientCaregiver(intakeRelationItem.Item_Id, personItem.Person_Id, intakeRelationItem.Person_Relationship_Type_Id, dateCreated, createdBy, isActive, isDeleted); if (newClientCareverModel == null) { status = "Error"; message = "A technical error has occurred! Please try again later"; } break; case (int)RelationTypeEnum.FamilyMembers: var clientFamilymemberModel = new ClientFamilyMemberModel(); var newClientFamilyMember = clientFamilymemberModel.EditClientFamilyMember(intakeRelationItem.Item_Id, personItem.Person_Id, intakeRelationItem.Person_Relationship_Type_Id, dateCreated, createdBy, isActive, isDeleted); if (newClientFamilyMember == null) { status = "Error"; message = "A technical error has occurred! Please try again later"; } break; case (int)RelationTypeEnum.FosterParents: var clientFosterParentModel = new ClientFosterParentModel(); var newFosterParent = clientFosterParentModel.EditClientFosterParent(intakeRelationItem.Item_Id, personItem.Person_Id, intakeRelationItem.IsDeceased, string.IsNullOrEmpty(intakeRelationItem.DateDeceased) ? (DateTime?)null : DateTime.Parse(intakeRelationItem.DateDeceased), dateCreated, createdBy, isActive, isDeleted); if (newFosterParent == null) { status = "Error"; message = "A technical error has occurred! Please try again later"; } break; case (int)RelationTypeEnum.ProspectiveAdoptiveParents: var clientProspectiveAdoptiveParentModel = new ProspectiveAdoptiveParentModel(); var newClientProspectiveAdoptiveParentsModel = clientProspectiveAdoptiveParentModel.EditClientProspectiveAdoptiveParents(intakeRelationItem.Item_Id, personItem.Person_Id, intakeRelationItem.Relation_Type_Id, dateCreated, createdBy, isActive, isDeleted); if (newClientProspectiveAdoptiveParentsModel == null) { status = "Error"; message = "A technical error has occurred! Please try again later"; } break; } } return(new JsonResult { Data = new { status, message } }); }
public ActionResult Edit(string id, string personId, string selectedRelationTypeId) { var personModel = new PersonModel(); var relatedPerson = personModel.GetSpecificPerson(int.Parse(personId)); var physicalAddress = relatedPerson.Addresses.Any(a => a.Address_Type_Id.Equals((int)AddressTypeEnum.PhysicalAddress)) ? relatedPerson.Addresses.First(a => a.Address_Type_Id.Equals((int)AddressTypeEnum.PhysicalAddress)) : new Address(); var postalAddress = relatedPerson.Addresses.Any(a => a.Address_Type_Id.Equals((int)AddressTypeEnum.PostalAddress)) ? relatedPerson.Addresses.First(a => a.Address_Type_Id.Equals((int)AddressTypeEnum.PostalAddress)) : new Address(); if (physicalAddress.Town != null) { physicalAddress.Selected_Local_Municipality_Id = physicalAddress.Town.Local_Municipality_Id; physicalAddress.Selected_Municipality_Id = physicalAddress.Town.Local_Municipality.District_Municipality_Id; physicalAddress.Selected_Province_Id = physicalAddress.Town.Local_Municipality.District.Province_Id; } if (postalAddress.Town != null) { postalAddress.Selected_Local_Municipality_Id = postalAddress.Town.Local_Municipality_Id; postalAddress.Selected_Municipality_Id = postalAddress.Town.Local_Municipality.District_Municipality_Id; postalAddress.Selected_Province_Id = postalAddress.Town.Local_Municipality.District.Province_Id; } var relationItem = new IntakeRelationItem() { Item_Id = int.Parse(id), Relation_Type_Id = int.Parse(selectedRelationTypeId), Person_Id = int.Parse(id), SearchPerson = new IntakeSearchViewModel() { Person_List = new List <Person>() }, CreatePerson = new PersonDetailViewModel() { Person = relatedPerson, PhysicalAddress = physicalAddress, PostalAddress = postalAddress } }; switch (int.Parse(selectedRelationTypeId)) { case (int)RelationTypeEnum.AdoptiveParents: var clientAdoptionModel = new ClientAdoptiveParentModel(); //var newAdoptiveParent = clientAdoptionModel.CreateClientAdoptiveParent(clientId, personItem.Person_Id, intakeRelationItem.IsDeceased, string.IsNullOrEmpty(intakeRelationItem.DateDeceased) ? (DateTime?)null : DateTime.Parse(intakeRelationItem.DateDeceased), dateCreated, createdBy, isActive, isDeleted); var adoptiveParent = clientAdoptionModel.GetSpecificClientAdoptiveParent(int.Parse(id)); if (adoptiveParent != null) { relationItem.IsDeceased = adoptiveParent.Is_Deceased != null && (bool)adoptiveParent.Is_Deceased; relationItem.DateDeceased = adoptiveParent.Date_Deceased == null ? string.Empty : ((DateTime)adoptiveParent.Date_Deceased).ToString("dd MMMM yyyy HH:mm:ss"); } break; case (int)RelationTypeEnum.ProspectiveAdoptiveParents: var PAPModel = new ProspectiveAdoptiveParentModel(); //var newAdoptiveParent = clientAdoptionModel.CreateClientAdoptiveParent(clientId, personItem.Person_Id, intakeRelationItem.IsDeceased, string.IsNullOrEmpty(intakeRelationItem.DateDeceased) ? (DateTime?)null : DateTime.Parse(intakeRelationItem.DateDeceased), dateCreated, createdBy, isActive, isDeleted); var pAP = PAPModel.GetSpecificProspectiveAdoptiveParent(int.Parse(id)); break; } relationItem.IsAdoptiveParentDetailVisible = int.Parse(selectedRelationTypeId) == (int)RelationTypeEnum.AdoptiveParents; relationItem.IsBiologicalParentDetailVisible = int.Parse(selectedRelationTypeId) == (int)RelationTypeEnum.BiologicalParents; relationItem.IsFosterParentDetailVisible = int.Parse(selectedRelationTypeId) == (int)RelationTypeEnum.FosterParents; relationItem.IsCaregiverDetailVisible = int.Parse(selectedRelationTypeId) == (int)RelationTypeEnum.Caregivers; relationItem.IsFamilyMemberDetailVisible = int.Parse(selectedRelationTypeId) == (int)RelationTypeEnum.FamilyMembers; relationItem.IsProspectiveAdoptiveParentVisible = int.Parse(selectedRelationTypeId) == (int)RelationTypeEnum.ProspectiveAdoptiveParents; return(PartialView("_RelationEdit", relationItem)); }