// GET: Tasks/Create public ActionResult Create(int?id) { ViewBag.ChildStatusListToChild = beneficiaryStatusService.FindAllChildStatuses().Where(x => !x.Description.Equals("Adulto")); ChildStatusHistory csh = new ChildStatusHistory(); csh.BeneficiaryID = id.Value; return(View(csh)); }
public ChildStatusHistory fetchByID(int childStatusHistoryID) { ChildStatusHistory childStatusHistory = UnitOfWork.Repository <ChildStatusHistory>().GetAll() .Include(x => x.ChildStatus) .Where(j => j.ChildStatusHistoryID == childStatusHistoryID) .FirstOrDefault(); return(childStatusHistory); }
public ActionResult EditPost(ChildStatusHistory csh) { if (ModelState.IsValid) { csh.LastUpdatedUserID = user.UserID; beneficiaryStatusService.SaveOrUpdate(csh); } return(RedirectToAction("Edit", "Beneficiaries", new { id = csh.BeneficiaryID })); }
public void SaveOrUpdate(ChildStatusHistory csh) { if (csh.ChildStatusHistoryID == 0) { ChildStatusHistoryRepository.Add(csh); } else { ChildStatusHistoryRepository.Update(csh); } this.Commit(); }
public ActionResult Delete(int id) { ChildStatusHistory csh = beneficiaryStatusService.fetchByID(id); { Beneficiary beneficiary = beneficiaryService.FetchById(csh.BeneficiaryID.Value); if (csh.ChildStatus.Description == "Initial" || csh.ChildStatus.Description == "Inicial" || csh.ChildStatus.Description == "Adult" || csh.ChildStatus.Description == "Adulto") { TempData["Error"] = "O estado Inicial ou Adulto não podem ser removidos."; return(RedirectToAction("Edit", "Beneficiaries", new { id = currentScreenID })); } beneficiaryStatusService.Delete(csh); return(RedirectToAction("Edit", "Beneficiaries", new { id = currentScreenID })); } }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ChildStatusHistory csh = beneficiaryStatusService.findByID(id.Value); ViewBag.ChildStatusListToChild = beneficiaryStatusService.FindAllChildStatuses().Where(x => !x.Description.Equals("Adulto")); if (csh == null) { return(HttpNotFound()); } //siteGoal.SitePerformanceComment = " "; return(View(csh)); }
public ActionResult Create(ChildStatusHistory csh) { if (ModelState.IsValid) { Beneficiary Beneficiary = beneficiaryService.FetchByBeneficiaryIDandStatusID(csh.BeneficiaryID.Value, csh.ChildStatusID.Value); if (Beneficiary != null) { csh.CreatedUserID = user.UserID; beneficiaryStatusService.SaveOrUpdate(csh); } else { TempData["Error"] = "A criança não poderá mudar de estágio se for igual ao anterior ou se tiver tornado adulta"; return(RedirectToAction("Edit", "Beneficiaries", new { id = csh.BeneficiaryID })); } } return(RedirectToAction("Edit", "Beneficiaries", new { id = csh.BeneficiaryID })); }
public ActionResult Create(Beneficiary Beneficiary) { ValidateModel(Beneficiary); if (ModelState.IsValid) { if (Beneficiary.HIVStatus.HIV == HIVStatus.POSITIVE && Beneficiary.HIVStatus.HIVInTreatment == null) { TempData["Error"] = LanguageResource.HIVStatus_Validation_HIVInTreatment_Required; } else if (Beneficiary.HIVStatus.HIV == HIVStatus.UNKNOWN && Beneficiary.HIVStatus.HIVUndisclosedReason == null) { TempData["Error"] = LanguageResource.HIVStatus_Validation_HIVUndisclosedReason_Required; } else if (Beneficiary.AgeInYears > 12) { TempData["Error"] = "O grupo de Poupança somente deve ser selecionado caso o Beneficiário tenha idade < 12 anos"; } else { var OtherKingship = db.SimpleEntities.Where(se => se.Type == "degree-of-kinship" && se.Description == "Outro").SingleOrDefault(); if (Beneficiary.KinshipToFamilyHeadID != OtherKingship.SimpleEntityID) { Beneficiary.OtherKinshipToFamilyHead = null; } if (Beneficiary.RegistrationDateDifferentFromHouseholdDate) { Beneficiary.RegistrationDate = Beneficiary.RegistrationDate; Beneficiary.HIVStatus.InformationDate = Beneficiary.RegistrationDate; } Beneficiary.HIVStatus.UserID = user.UserID; if (Beneficiary.HIVStatus.HIV == HIVStatus.POSITIVE) { Beneficiary.HIVStatus.HIVUndisclosedReason = -1; if (Beneficiary.HIVStatus.HIVInTreatment != HIVStatus.IN_TARV) { Beneficiary.HIVStatus.TarvInitialDate = null; } } else if (Beneficiary.HIVStatus.HIV == HIVStatus.UNKNOWN) { Beneficiary.HIVStatus.NID = null; Beneficiary.HIVStatus.HIVInTreatment = -1; Beneficiary.HIVStatus.TarvInitialDate = null; } else { Beneficiary.HIVStatus.NID = null; Beneficiary.HIVStatus.HIVInTreatment = -1; Beneficiary.HIVStatus.HIVUndisclosedReason = -1; Beneficiary.HIVStatus.TarvInitialDate = null; } Beneficiary.CreatedUserID = user.UserID; beneficiaryService.Save(Beneficiary); beneficiaryService.Commit(); Beneficiary.HIVStatus.BeneficiaryID = Beneficiary.BeneficiaryID; Beneficiary.HIVStatus.BeneficiaryGuid = Beneficiary.Beneficiary_guid; hivStatusService.SaveOrUpdate(Beneficiary.HIVStatus); hivStatusService.Commit(); ChildStatusHistory csh = new ChildStatusHistory(); csh.BeneficiaryID = Beneficiary.BeneficiaryID; csh.CreatedUserID = user.UserID; csh.BeneficiaryGuid = Beneficiary.Beneficiary_guid; csh.ChildStatusID = beneficiaryStatusService.FindChildStatusByDescription("Inicial").StatusID; beneficiaryStatusService.SaveOrUpdate(csh); beneficiaryStatusService.Commit(); TempData["success"] = Domain.Resources.LanguageResource.Global_Operation_successfully_realized; return(RedirectToAction("Edit", new { id = Beneficiary.BeneficiaryID })); } } Beneficiary.DateOfBirth = DateTime.Now; ViewBag.Kinships = db.SimpleEntities.Where(se => se.Type == "degree-of-kinship" && se.Code != "99").ToList(); ViewBag.OVCTypes = db.OVCTypes.Where(o => o.Description != "Indeterminado").ToList(); return(View(Beneficiary)); }
public int ImportData(string path) { UnitOfWork.DbContext.Configuration.AutoDetectChangesEnabled = false; FileImporter imp = new FileImporter(); string fullPah = path + @"\ChildStatusHistories.csv"; string lastGuidToImport = null; int ImportedChildStatusHistory = 0; List <User> UDB = UnitOfWork.Repository <User>().GetAll().ToList(); List <UniqueEntity> BeneficiariesDB = FindAllBeneficiaryUniqueEntities(); List <UniqueEntity> ChildStatusHistoriesDB = FindAllChildStatusHistoryUniqueEntities(); List <ChildStatusHistory> ChildStatusHistoryToPersist = new List <ChildStatusHistory>(); IEnumerable <DataRow> ChildStatusRows = imp.ImportFromCSV(fullPah).Rows.Cast <DataRow>(); try { foreach (DataRow row in ChildStatusRows) { Guid ChildStatusHistoryGuid = new Guid(row["childstatushistory_guid"].ToString()); if (FindBySyncGuid(ChildStatusHistoriesDB, ChildStatusHistoryGuid) == null) { UniqueEntity BeneficiaryUE = null; lastGuidToImport = ChildStatusHistoryGuid.ToString(); User user = UDB.Where(x => x.SyncGuid == new Guid(row["CreatedUserGuid"].ToString())).SingleOrDefault(); ChildStatusHistory childStatusHistory = new ChildStatusHistory { EffectiveDate = DateTime.Parse(row["EffectiveDate"].ToString()), CreatedDate = DateTime.Parse(row["CreatedDate"].ToString()), ChildStatusID = int.Parse(row["ChildStatusID"].ToString()), CreatedUserID = user == null ? 1 : user.UserID, SyncGuid = ChildStatusHistoryGuid, SyncDate = DateTime.Now }; if (!isZerosGuid(row["BeneficiaryGuid"].ToString())) { childStatusHistory.BeneficiaryGuid = new Guid(row["BeneficiaryGuid"].ToString()); BeneficiaryUE = FindBySyncGuid(BeneficiariesDB, childStatusHistory.BeneficiaryGuid); if (BeneficiaryUE != null) { childStatusHistory.BeneficiaryID = BeneficiaryUE.ID; } } if (isZerosGuid(row["CreatedUserGuid"].ToString())) { _logger.Error("Não foi encontrado nenhum usuário com Guid '{0}'. A autoria da criacao deste estado sera do usuario com ID = 1", row["CreatedUserGuid"].ToString()); } if (BeneficiaryUE == null) { _logger.Error("Estado do Beneficiarios não tem o Guid do Beneficiario, actualmente o valor é '{0}'. O Estado com Guid '{1}' nao sera importado.", row["BeneficiaryGuid"].ToString(), ChildStatusHistoryGuid); } else { ChildStatusHistoryToPersist.Add(childStatusHistory); ImportedChildStatusHistory++; } } if (ImportedChildStatusHistory % 100 == 0) { _logger.Information(ImportedChildStatusHistory + " de " + ChildStatusRows.Count() + " Estados de Crianca importados."); } } ChildStatusHistoryToPersist.ForEach(csh => UnitOfWork.Repository <ChildStatusHistory>().Add(csh)); UnitOfWork.Commit(); Rename(fullPah, fullPah + IMPORTED); } catch (Exception e) { _logger.Information("Erro ao importar o Guid : " + lastGuidToImport); _logger.Error(e, "Erro ao importar Criancas", null); throw e; } return(ChildStatusHistoryToPersist.Count()); }
public void Delete(ChildStatusHistory csh) { ChildStatusHistoryRepository.Delete(csh); this.Commit(); }