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 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 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 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); }
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(); } }
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)); }
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)); }