public static bool AddNewAudit(RayimContext context, int numberOfAuditRecords, int serviceId) { Random random = new Random(DateTime.Now.Millisecond); var cunsumersIds = context.ConsumerServices. Where(x => x.ServiceId == serviceId). Select(x => x.ConsumerId.Value).ToList().Distinct(). OrderBy(x => random.Next()). Take(numberOfAuditRecords).ToList(); if (cunsumersIds.Any()) { var newAudit = new Audit() { AuditDate = DateTime.Now.Date, ServiceId = serviceId }; context.Audits.Add(newAudit); var consumers = context.Consumers.Where(x => cunsumersIds.Contains(x.ConsumerId)).ToList(); consumers.ForEach(x => { newAudit.Consumers.Add(x); }); context.SaveChanges(); } return(cunsumersIds.Any()); }
public static void LogError(Exception ex) { String additionalErrorInfo = ""; if (ex is DbEntityValidationException) { additionalErrorInfo += "\r\n"; foreach (var eve in ((DbEntityValidationException)ex).EntityValidationErrors) { additionalErrorInfo += String.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { additionalErrorInfo += String.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } additionalErrorInfo += "\r\n"; } } Log log = new Log(); log.Date = DateTime.Now; if (ex.InnerException != null) { log.InnerException = ex.InnerException.ToString(); } log.Message = ex.Message; log.Source = ex.Source; log.StackTrace = additionalErrorInfo + ex.StackTrace; using (RayimContext cont = new RayimContext()) { cont.Logs.Add(log); cont.SaveChanges(); } }
public static UserModel GetUserByEmail(string userEmail) { using (var context = new RayimContext()) { return(GetUserByEmail(userEmail, context)); } }
protected override void OnActionExecuting(ActionExecutingContext filterContext) { _context = new RayimContext(); ApplicationUser = new ApplicationUser(); if (this.User != null) { if (this.User.Identity.IsAuthenticated) { ViewBag.UserName = this.User.Identity.Name; Task <ApplicationUser> user = UserManager.FindByEmailAsync(ViewBag.UserName); user.Wait(); ApplicationUser = user.Result; if (_context == null) { _context = new RayimContext(); } UserManagment userManagment = new UserManagment(_context); ConsumerManagement cm = new ConsumerManagement(_context); SystemUser userModel = userManagment.GetUserSync(ApplicationUser.Id); var contact = cm.GetContactByEmail(User?.Identity?.Name ?? ""); CurrentUserModelView modelView = new CurrentUserModelView(userModel); ViewData["CurrentUser"] = modelView; var contactData = new ContactViewModel(contact ?? new Core.Models.ContactModel()); ViewData["loggedContact"] = JsonConvert.SerializeObject(contactData); } } base.OnActionExecuting(filterContext); }
public static List <FileMetaDataModel> GetFilesByConsumerServicesId(int id) { using (RayimContext context = new RayimContext()) { var files = context.FileMetaDatas.Where(x => x.ParentEntityId == id && x.ParentEntityTypeId == (int)EntityTypes.ConsumerServices).ToList(); return(CustomMapper.MapList <FileMetaDataModel, FileMetaData>(files)); } }
public static void Delete(RayimContext context, int id) { var entity = context.ConsumerMedicaidNumbers.FirstOrDefault(x => x.Id == id); if (entity != null) { context.ConsumerMedicaidNumbers.Remove(entity); context.SaveChanges(); } }
public static bool Validate(RayimContext context, BaseConsumerServiceCoordinatorModel model) { var intersectedRecord = context.ConsumerServiceCoordinators.FirstOrDefault(x => x.Id != model.Id && x.ConsumerId == model.ConsumerId && (x.FromDate <= model.FromDate && (x.ToDate == null || model.FromDate <= x.ToDate) || model.ToDate != null && x.FromDate <= model.ToDate && (x.ToDate == null || model.ToDate <= x.ToDate) || x.FromDate >= model.FromDate && (model.ToDate == null || model.ToDate >= x.ToDate && x.ToDate != null) || model.ToDate == null && x.ToDate == null)); return(intersectedRecord == null); }
public static void Delete(RayimContext context, int id) { var dbEntity = context.ConsumerServiceCoordinators.FirstOrDefault(x => x.Id == id); if (dbEntity != null) { context.ConsumerServiceCoordinators.Remove(dbEntity); context.SaveChanges(); } }
public static bool DeleteAudit(RayimContext context, int id) { var audit = context.Audits.FirstOrDefault(x => x.Id == id); if (audit != null) { context.Audits.Remove(audit); context.SaveChanges(); } return(audit != null); }
private static bool ValidateDateRange(RayimContext context, ConsumerMedicaidNumberModel model) { var intersectedRecord = context.ConsumerMedicaidNumbers .FirstOrDefault(x => x.Id != model.Id && x.ConsumerId == model.ConsumerId && (x.FromDate <= model.FromDate && (x.ToDate == null || model.FromDate <= x.ToDate) || model.ToDate != null && x.FromDate <= model.ToDate && (x.ToDate == null || model.ToDate <= x.ToDate) || x.FromDate >= model.FromDate && (model.ToDate == null || model.ToDate >= x.ToDate && x.ToDate != null) || model.ToDate == null && x.ToDate == null)); return(intersectedRecord == null); }
public void CalculateTemplatePath(DateTime?templateDate, RayimContext context) { String templatePath = String.Empty; if (templateDate.HasValue) { templatePath = context.ReportTemplates .FirstOrDefault(x => x.ReportType.Name == ReportTypeName.ToString() && x.StartDate == templateDate).ReportPath; } ReportPath = String.IsNullOrEmpty(templatePath) ? DefaultReportPath : templatePath; }
public static List <AuditModel> GetAudits(RayimContext context, DateTime?auditDate = null) { var dbAudits = context.Audits.Where(x => auditDate == null || x.AuditDate <= auditDate).ToList(); var modelAudits = dbAudits.Select(x => { var result = CustomMapper.MapEntity <AuditModel>(x); result.Consumers = CustomMapper.MapList <ConsumerModel, Database.Consumer>(x.Consumers.ToList()); return(result); }).ToList(); return(modelAudits); }
public static FileMetaDataModel SaveFileMetaData(RayimContext context, FileMetaDataModel model) { bool isNew = model.Id == 0; FileMetaData dbFileData = context.FileMetaDatas.FirstOrDefault(x => x.Id == model.Id) ?? new FileMetaData(); CustomMapper.MapEntity(model, dbFileData); if (isNew) { context.FileMetaDatas.Add(dbFileData); } context.SaveChanges(); return(CustomMapper.MapEntity <FileMetaDataModel>(dbFileData)); }
public static Boolean DeleteFileData(RayimContext context, int fileId) { FileMetaData dbFileData = context.FileMetaDatas.FirstOrDefault(x => x.Id == fileId); if (dbFileData != null) { if (!string.IsNullOrEmpty(dbFileData.FilePath)) { IOFileService.DeleteFile(dbFileData.FilePath); } context.FileMetaDatas.Remove(dbFileData); context.SaveChanges(); } return(dbFileData != null); }
public static void LogError(String str) { Log log = new Log(); log.Date = DateTime.Now; log.InnerException = null; log.Message = "Looged string"; log.Source = "Hamaspik.WebApi"; log.StackTrace = str; using (RayimContext cont = new RayimContext()) { cont.Logs.Add(log); cont.SaveChanges(); } }
private static void ProcessOldData(RayimContext context, FileMetaDataModel model, string fileData) { if (model.Id > 0) { FileMetaData dbFileData = context.FileMetaDatas.FirstOrDefault(x => x.Id == model.Id) ?? new FileMetaData(); if (!string.IsNullOrEmpty(fileData) && !string.IsNullOrEmpty(dbFileData.FilePath)) { IOFileService.DeleteFile(dbFileData.FilePath); } if (string.IsNullOrEmpty(fileData)) { model.FilePath = dbFileData.FilePath; } } }
public static List <string> Validate(RayimContext context, ConsumerMedicaidNumberModel model) { var errors = new List <string>(); if (!ValidateDateRange(context, model)) { errors.Add("Not valid date range for Medicaid number"); } if (!ValidateMedicaidNumber(context, model)) { errors.Add("This Medicaid number already exists"); } return(errors); }
public static ConsumerMedicaidNumberModel CreateOrUpdate(RayimContext context, ConsumerMedicaidNumberModel model) { var dbEntity = context.ConsumerMedicaidNumbers.FirstOrDefault(x => x.Id == model.Id); if (dbEntity == null) { var map = CustomMapper.MapEntity <ConsumerMedicaidNumber>(model); dbEntity = context.ConsumerMedicaidNumbers.Add(map); } else { CustomMapper.MapEntity <ConsumerMedicaidNumber>(model, dbEntity); } context.SaveChanges(); return(CustomMapper.MapEntity <ConsumerMedicaidNumberModel>(dbEntity)); }
public static ConsumerAddressModel CreateOrUpdate(RayimContext context, BaseConsumerAddressModel inputModel) { var isNew = inputModel.Id == 0; var dbEntity = context.ConsumerAddresses.FirstOrDefault(x => x.Id == inputModel.Id); if (dbEntity == null) { dbEntity = context.ConsumerAddresses.Add(CustomMapper.MapEntity <ConsumerAddress>(inputModel)); } else { CustomMapper.MapEntity <ConsumerAddress>(inputModel, dbEntity); } context.SaveChanges(); return(CustomMapper.MapEntity <ConsumerAddressModel>(dbEntity)); }
protected override void Dispose(bool disposing) { if (disposing) { if (_userManager != null) { _userManager.Dispose(); _userManager = null; } if (_signInManager != null) { _signInManager.Dispose(); _signInManager = null; } if (_context != null) { _context.Dispose(); } _context = null; } base.Dispose(disposing); }
public static ConsumerServiceCoordinatorModel CreateOrUpdate(RayimContext context, BaseConsumerServiceCoordinatorModel inputModel) { var isNew = inputModel.Id == 0; var dbEntity = context.ConsumerServiceCoordinators.FirstOrDefault(x => x.Id == inputModel.Id); if (dbEntity == null) { dbEntity = context.ConsumerServiceCoordinators.Add(CustomMapper.MapEntity <ConsumerServiceCoordinator>(inputModel)); } else { CustomMapper.MapEntity <ConsumerServiceCoordinator>(inputModel, dbEntity); } context.SaveChanges(); if (isNew) { context.Entry(dbEntity).Reference(c => c.Contact).Load();; } return(CustomMapper.MapEntity <ConsumerServiceCoordinatorModel>(dbEntity)); }
public static FileMetaDataModel SaveFileDataWithFile(RayimContext context, FileMetaDataModel model, string fileData) { ProcessOldData(context, model, fileData); SaveFile(model, fileData); return(SaveFileMetaData(context, model)); }
public static List <FileMetaDataModel> GetConsumerFiles(RayimContext context, int consumerId) { var dbFiles = context.FileMetaDatas.Where(x => x.ParentEntityId == consumerId && x.ParentEntityTypeId == (int)EntityTypes.Consumer).ToList(); return(CustomMapper.MapList <FileMetaDataModel, FileMetaData>(dbFiles)); }
public static FileMetaDataModel GetFileMetadata(RayimContext context, int fileId) { var dbEntity = context.FileMetaDatas.FirstOrDefault(x => x.Id == fileId); return(CustomMapper.MapEntity <FileMetaDataModel>(dbEntity)); }
public ConsumerNotesManagement(RayimContext context) : base(context) { }
public ConsumerHabReviewsManagement(RayimContext context) : base(context) { }
public static Contact GetScheduledContactByDate(RayimContext context, DateTime planOfDate, Int32 consumerId) { var foundRecord = context.ConsumerServiceCoordinators.FirstOrDefault(x => x.ConsumerId == consumerId && x.FromDate <= planOfDate && planOfDate <= x.ToDate); return(foundRecord?.Contact); }
public ConsumerHabPlansManagement(RayimContext context) : base(context) { }
public EmployeeManagment(RayimContext context) : base(context) { }
public ConsumerServicesManagement(RayimContext context) : base(context) { }