public long UpdateUser(UserModel user) { try { if (string.IsNullOrEmpty(user.Id)) { return(-2); } var userEntities = _context.AspNetUsers.Where(m => m.Id == user.Id).ToList(); if (!userEntities.Any()) { return(-2); } var userEntity = userEntities[0]; userEntity.FirstName = user.FirstName; userEntity.LastName = user.LastName; userEntity.UserName = user.UserName; userEntity.Email = user.Email; if (!string.IsNullOrEmpty(user.Password)) { userEntity.PasswordHash = PasswordManager.HashPassword(user.Password); } _context.Entry(userEntity).State = EntityState.Modified; if (!string.IsNullOrEmpty(user.Role)) { var rr = _context.AspNetUserRoles.Where(r => r.UserId == user.Id).ToList(); if (!rr.Any()) { var role = new AspNetUserRoles { UserId = userEntity.Id, RoleId = user.Role }; _context.AspNetUserRoles.Add(role); } else { var role = rr[0]; if (role.RoleId != user.Role) { role.RoleId = user.Role; _context.Entry(role).State = EntityState.Modified; } } } _context.SaveChanges(); return(5); } catch (Exception e) { return(0); } }
public int AddTXCurrs(List <TXCurrImport> tXCurrs) { try { var processed = 0; if (!tXCurrs.Any()) { return(0); } tXCurrs.ForEach(site => { var siteO = _context.Site.Include("SiteTxTarget").Where(s => s.SiteId.Trim().ToLower() == site.SiteId.Trim().ToLower()).ToList(); if (siteO.Any()) { var tt = siteO.ToList()[0]; if (!tt.SiteTxTarget.Any(r => r.FiscalYear == site.FISCAL_YEAR)) { var siteEntity = new SiteTxTarget { SiteId = tt.Id, TxCurrTarget = site.TX_CURR_TARGET, TxNewTarget = site.TX_NEW_TARGET, FiscalYear = site.FISCAL_YEAR }; _context.SiteTxTarget.Add(siteEntity); processed++; } else { var t = tt.SiteTxTarget.ToList()[0]; t.TxCurrTarget = site.TX_CURR_TARGET; t.TxNewTarget = site.TX_NEW_TARGET; _context.Entry(t).State = EntityState.Modified; processed++; } } else { } }); _context.SaveChanges(); return(processed); } catch (Exception ex) { return(0); } }
public int AddPatientList(List <PatientDemographyModel> patients) { try { var processed = 0; if (!patients.Any()) { return(-1); } patients.ForEach(patient => { var duplicates = _context.PatientDemography.Where(m => m.PatientIdentifier.Trim().ToLower() == patient.PatientIdentifier.Trim().ToLower()); if (!duplicates.Any()) { var patientEntity = mapper.Map <PatientDemographyModel, PatientDemography>(patient); _context.PatientDemography.Add(patientEntity); processed++; } else { var entity = duplicates.ToList()[0]; entity.PatientDieFromThisIllness = patient.PatientDieFromThisIllness; entity.OtherIdtypeCode = patient.OtherIdtypeCode; entity.OtherIdnumber = patient.OtherIdnumber; entity.ConditionCode = patient.ConditionCode; entity.PatientAge = patient.PatientAge; entity.DiagnosisDate = patient.DiagnosisDate; entity.DateOfLastReport = patient.DateOfLastReport; entity.DateOfFirstReport = patient.DateOfFirstReport; entity.HospitalNumber = patient.HospitalNumber; entity.EnrolledInHivcareDate = patient.EnrolledInHivcareDate; entity.TransferredOutStatus = patient.TransferredOutStatus; entity.ArtstartDate = patient.ArtstartDate; entity.FirstConfirmedHivtestDate = patient.FirstConfirmedHivtestDate; entity.ProgramAreaCode = patient.ProgramAreaCode; _context.Entry(entity).State = EntityState.Modified; processed++; } }); return(processed); } catch (Exception ex) { return(-1); } }
public long UpdateRegimen(RegimenModel regimen) { try { if (regimen == null || regimen.Id < 1) { return(-2); } var regimenEntities = _context.Regimen.Where(m => m.Id == regimen.Id).ToList(); if (!regimenEntities.Any()) { return(-2); } var regimenEntity = regimenEntities[0]; regimenEntity.Combination = regimen.Combination; regimenEntity.Line = regimen.Line; regimenEntity.Code = regimen.Code; _context.Entry(regimenEntity).State = EntityState.Modified; _context.SaveChanges(); return(regimenEntity.Id); } catch (Exception ex) { // Log Error return(0); } }