private void AutoUploadDocument <T>(T document) where T : Document { using (var context = new ConnectContext()) { var companyKey = FetchClaimValue(ConnectConstants.ConnectCompanyKeyClaim); var existingDocument = FindDocuments <T>(context, document.RegistrationNumber, companyKey); bool hasExisting = existingDocument.Any(); foreach (var item in existingDocument) { if (item.Equals(document)) { hasExisting = true; break; } } if (!hasExisting) { document.UserId = GetUserId(); context.Set <T>().Add(document); context.SaveChanges(); var serializedData = new SerializedData { DocumentType = typeof(T).FullName, DocumentId = document.Id, Data = document.SerializedData }; context.Set <SerializedData>().Add(serializedData); context.SaveChanges(); } } }
private void UpdateDocument <T>(T document) where T : Document { using (var context = new ConnectContext()) { var companyKey = FetchClaimValue(ConnectConstants.ConnectCompanyKeyClaim); var existingDocument = FindDocument <T>(context, document.RegistrationNumber, companyKey); if (existingDocument != null) { document.Id = existingDocument.Id; document.UserId = GetUserId(); context.Entry(existingDocument).CurrentValues.SetValues(document); context.SaveChanges(); var documentType = typeof(T).FullName; var serializedData = context.SerializedData.FirstOrDefault(c => c.DocumentId == document.Id && c.DocumentType == documentType); if (serializedData != null) { serializedData.Data = document.SerializedData; context.SaveChanges(); } } } }
private void AutoUploadReport <T>(T report) where T : BaseReport { using (var context = new ConnectContext()) { var existingDocument = FindReports <T>(context, report.CentreName); bool hasExisting = existingDocument.Any(); foreach (var item in existingDocument) { if (item.Equals(report)) { hasExisting = true; break; } } if (!hasExisting) { report.Id = 0; report.User = null; report.ConnectUserId = GetUserId(); context.Set <T>().Add(report); context.SaveChanges(); } } }
public void UploadTechnician(Technician technician) { using (var context = new ConnectContext()) { var userId = GetUserId(); technician.UserId = userId; technician.Uploaded = DateTime.Now; var technicians = context.Technicians.Where(c => c.UserId == userId); var technicianId = 0; var match = technicians.FirstOrDefault(c => string.Equals(c.Name, technician.Name) && string.Equals(c.Number, technician.Number)); if (match != null) { technicianId = match.Id; } technician.Id = technicianId; if (technicianId == 0) { context.Set <Technician>().Add(technician); } else { context.Entry(match).CurrentValues.SetValues(technician); } context.SaveChanges(); } }
private void UploadDocument <T>(T document) where T : Document { using (var context = new ConnectContext()) { document.UserId = GetUserId(); context.Set <T>().Add(document); context.SaveChanges(); var serializedData = new SerializedData { DocumentType = typeof(T).FullName, DocumentId = document.Id, Data = document.SerializedData }; context.Set <SerializedData>().Add(serializedData); context.SaveChanges(); } }
public void UploadCustomerContact(CustomerContact customerContact) { using (var context = new ConnectContext()) { customerContact.UserId = GetUserId(); customerContact.Uploaded = DateTime.Now; context.CustomerContacts.Add(customerContact); context.SaveChanges(); } }
private void UploadReport <T>(T report) where T : BaseReport { using (var context = new ConnectContext()) { report.Id = 0; report.User = null; report.ConnectUserId = GetUserId(); context.Set <T>().Add(report); context.SaveChanges(); } }
private static Exception IsAuthorized(IConnectKeys connectKeys) { Exception result = null; if (!LicenseManager.IsValid(connectKeys.LicenseKey.ToString())) { return(new FaultException("The license key is invalid or has expired.")); } try { using (var context = new ConnectContext()) { var company = context.Users.FirstOrDefault(c => c.CompanyKey == connectKeys.CompanyKey); if (company == null) { result = new FaultException("Your computer is not currently authorized to use Connect at this time."); } if (result == null) { var connectUserNode = context.UserNodes.FirstOrDefault(c => c.MachineKey == connectKeys.MachineKey && c.CompanyKey == connectKeys.CompanyKey); if (connectUserNode == null) { var connectUser = context.Users.FirstOrDefault(c => c.CompanyKey == connectKeys.CompanyKey); if (connectUser == null) { result = new FaultException("Your computer is not currently authorized to use Connect at this time."); return(result); } context.UserNodes.Add(new ConnectUserNode(connectKeys) { IsAuthorized = true, ConnectUser = connectUser }); context.SaveChanges(); return(null); } if (!connectUserNode.IsAuthorized) { result = new FaultException("Your computer is not currently authorized to use Connect at this time."); } } } } catch (Exception ex) { result = new FaultException("An unexcepted error occurred; " + ex.Message); } return(result); }
public void UploadDetailedException(DetailedException detailedException) { using (var context = new ConnectContext()) { var existing = context.DetailedExceptions.Any(c => c.ExceptionDetails == detailedException.ExceptionDetails); if (!existing) { detailedException.UserId = GetUserId(); context.DetailedExceptions.Add(detailedException); context.SaveChanges(); } } }
public void UploadWorkshopSettings(WorkshopSettings workshopSettings) { using (var context = new ConnectContext()) { workshopSettings.Id = 0; workshopSettings.UserId = GetUserId(); workshopSettings.Uploaded = DateTime.Now; if (workshopSettings.Created == default(DateTime) || workshopSettings.Created == _sqlDefaultDateTime) { workshopSettings.Created = DateTime.Now; } context.Set <WorkshopSettings>().Add(workshopSettings); context.SaveChanges(); } }