public string AddUser(UserModel user) { try { var userEntities = _context.AspNetUsers.Where(m => m.Email == user.Email).ToList(); if (userEntities.Any()) { return("-3"); } var userEntity = mapper.Map <UserModel, AspNetUsers>(user); userEntity.Id = Guid.NewGuid().ToString(); userEntity.SecurityStamp = Guid.NewGuid().ToString("D"); userEntity.EmailConfirmed = true; userEntity.PasswordHash = PasswordManager.HashPassword(user.Password); _context.AspNetUsers.Add(userEntity); _context.SaveChanges(); if (!string.IsNullOrEmpty(user.Role)) { var role = new AspNetUserRoles { UserId = userEntity.Id, RoleId = user.Role }; _context.AspNetUserRoles.Add(role); _context.SaveChanges(); } return(userEntity.Id); } catch (Exception e) { return(null); } }
public long AddSite(SiteModel site) { try { if (site == null) { return(-2); } var duplicates = _context.Site.Count(m => m.SiteId.Trim().ToLower() == site.SiteId.Trim().ToLower()); if (duplicates > 0) { return(-3); } var siteEntity = mapper.Map <SiteModel, Site>(site); if (string.IsNullOrEmpty(siteEntity.SiteId)) { return(-2); } _context.Site.Add(siteEntity); _context.SaveChanges(); return(siteEntity.Id); } catch (Exception e) { return(0); } }
public long AddRegimen(RegimenModel regimen) { try { if (regimen == null) { return(-2); } var duplicates = _context.Regimen.Count(m => m.Combination.Trim().ToLower() == regimen.Combination.Trim().ToLower() && m.Code == regimen.Code); if (duplicates > 0) { return(-3); } var regimenEntity = mapper.Map <RegimenModel, Regimen>(regimen); _context.Regimen.Add(regimenEntity); _context.SaveChanges(); return(regimenEntity.Id); } catch (Exception e) { return(0); } }
public long AddPatient(PatientDemographyModel patient) { try { if (patient == null) { return(-2); } var duplicates = _context.PatientDemography.Count(m => m.PatientIdentifier.Trim().ToLower() == patient.PatientIdentifier.Trim().ToLower()); if (duplicates > 0) { return(-3); } var sites = _context.Site.Where(m => m.SiteId.Trim().ToLower() == patient.FacilityId.Trim().ToLower()).ToList(); if (!sites.Any()) { return(-3); } var patientEntity = mapper.Map <PatientDemographyModel, PatientDemography>(patient); _context.PatientDemography.Add(patientEntity); _context.SaveChanges(); return(patientEntity.Id); } catch (Exception e) { return(0); } }