public long UpdateApplicationItems(List <ApplicationItemObject> importItems, List <ApplicationItemObject> oldImportItems, long applicationId) { try { if (!importItems.Any()) { return(-2); } var successCount = 0; using (var db = new ImportPermitEntities()) { var existingItems = db.ApplicationItems.Where(v => v.ApplicationId == applicationId).ToList(); importItems.ForEach(importItem => { var existingItem = existingItems.Find(o => o.ProductId == importItem.ProductId); if (existingItem != null && existingItem.Id > 0) { existingItem.EstimatedQuantity = importItem.EstimatedQuantity; existingItem.EstimatedValue = importItem.EstimatedValue; existingItem.PSFNumber = importItem.PSFNumber; existingItem.ReferenceLicenseCode = importItem.ReferenceLicenseCode; db.Entry(existingItem).State = EntityState.Modified; db.SaveChanges(); successCount += 1; } else { importItem.ApplicationId = applicationId; var importItemEntity = ModelMapper.Map <ApplicationItemObject, ApplicationItem>(importItem); if (importItemEntity != null && importItemEntity.ApplicationId > 0) { db.ApplicationItems.Add(importItemEntity); db.SaveChanges(); successCount += 1; } } }); oldImportItems.ForEach(importItem => { if (!importItems.Exists(h => h.ProductId == importItem.ProductId)) { var myItems = db.ApplicationItems.Where(m => m.ProductId == importItem.ProductId && m.ApplicationId == importItem.ApplicationId).ToList(); if (myItems.Any()) { db.ApplicationItems.Remove(myItems[0]); db.SaveChanges(); } } }); return(successCount); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long UpdateImporterDepotAndPerson(UserProfileObject person) { try { if (person == null) { return(-2); } using (var db = new ImportPermitEntities()) { var existing = db.Importers.Where(i => i.Id == person.CompanyId).ToList(); if (!existing.Any()) { return(-2); } var importer = existing[0]; var existingDepot = db.Depots.Where(i => i.ImporterId == importer.Id).ToList(); if (!existingDepot.Any()) { return(-2); } var existingp = db.People.Where(i => i.Id == person.PersonId).ToList(); if (!existingp.Any()) { return(-2); } importer.Name = person.CompanyName; importer.IsActive = person.IsActive; var prs = existingp[0]; prs.FirstName = person.FirstName; prs.LastName = person.LastName; var depotEntity = existingDepot[0]; depotEntity.Name = person.CompanyName; db.Entry(importer).State = EntityState.Modified; db.SaveChanges(); db.Entry(prs).State = EntityState.Modified; db.SaveChanges(); db.Entry(depotEntity).State = EntityState.Modified; db.SaveChanges(); return(importer.Id); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long AddThroughPut(ThroughPutObject throughPut) { try { if (throughPut == null) { return(-2); } var documentEntity = ModelMapper.Map <DocumentObject, Document>(throughPut.DocumentObject); if (documentEntity == null || documentEntity.DocumentTypeId < 1) { return(-2); } using (var db = new ImportPermitEntities()) { var throughPutEntities = (from th in db.ThroughPuts.Where(th => th.Id == throughPut.Id) join appItem in db.ApplicationItems on th.ApplicationItemId equals appItem.Id join app in db.Applications on appItem.ApplicationId equals app.Id select new { th, app }).ToList(); if (!throughPutEntities.Any()) { return(-2); } var throughPutEntity = throughPutEntities[0].th; var appEntity = throughPutEntities[0].app; var docEntity = db.Documents.Add(documentEntity); db.SaveChanges(); var appDoc = new ApplicationDocument { DocumentId = docEntity.DocumentId, ApplicationId = appEntity.Id }; db.ApplicationDocuments.Add(appDoc); db.SaveChanges(); throughPutEntity.DocumentId = docEntity.DocumentId; throughPutEntity.Quantity = throughPut.Quantity; throughPutEntity.IPAddress = throughPut.IPAddress; db.Entry(throughPutEntity).State = EntityState.Modified; db.SaveChanges(); return(throughPutEntity.Id); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long AddProduct(ProductObject product) { try { if (product == null) { return -2; } var productEntity = ModelMapper.Map<ProductObject, Product>(product); if (productEntity == null || string.IsNullOrEmpty(productEntity.Name)) { return -2; } using (var db = new ImportPermitEntities()) { if (db.Products.Count(m => m.Code.ToLower() == product.Code.ToLower() && m.Name.ToLower() == product.Name.ToLower()) >0) { return -3; } var returnStatus = db.Products.Add(productEntity); db.SaveChanges(); var requirements = new List<ProductDocumentRequirementObject>(); if (product.ProductDocumentRequirementObjects != null) { requirements = product.ProductDocumentRequirementObjects.ToList(); } if (requirements.Any()) { requirements.ToList().ForEach(k => { if (db.ProductDocumentRequirements.Count(m => m.ProductId == product.ProductId && m.DocumentTypeId == k.DocumentTypeId) < 1) { k.ProductId = returnStatus.ProductId; var productReqEntity = ModelMapper.Map<ProductDocumentRequirementObject, ProductDocumentRequirement>(k); if (productReqEntity != null && productReqEntity.DocumentTypeId > 0 && productReqEntity.ProductId > 0) { db.ProductDocumentRequirements.Add(productReqEntity); db.SaveChanges(); } } }); } return returnStatus.ProductId; } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return 0; } }
public long SaveNotificationDocumentUpdateDepot(DocumentObject document) { try { if (document == null) { return(-2); } var documentEntity = ModelMapper.Map <DocumentObject, Document>(document); if (documentEntity == null || string.IsNullOrEmpty(documentEntity.DocumentPath)) { return(-2); } using (var db = new ImportPermitEntities()) { var ntDoc = db.Documents.Add(documentEntity); db.SaveChanges(); var notifications = db.Notifications.Where(x => x.Id == document.NotificationId).ToList(); if (!notifications.Any()) { return(-2); } var app = new NotificationDocument { DocumentId = ntDoc.DocumentId, NotificationId = document.NotificationId, DateAttached = document.DateUploaded, Comment = document.Comment }; var dx = db.NotificationDocuments.Add(app); db.SaveChanges(); if (dx.Id < 1) { db.Documents.Remove(ntDoc); return(0); } var notification = notifications[0]; notification.DischargeDepotId = document.DepotId; db.Entry(notification).State = EntityState.Modified; db.SaveChanges(); return(ntDoc.DocumentId); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long AddStorageProviderType(StorageProviderTypeObject storageProviderType) { try { if (storageProviderType == null) { return(-2); } var storageProviderTypeEntity = ModelMapper.Map <StorageProviderTypeObject, StorageProviderType>(storageProviderType); if (storageProviderTypeEntity == null || string.IsNullOrEmpty(storageProviderTypeEntity.Name)) { return(-2); } using (var db = new ImportPermitEntities()) { if (db.StorageProviderTypes.Count(m => m.Name.ToLower() == storageProviderType.Name.ToLower() && m.Name.ToLower() == storageProviderType.Name.ToLower()) > 0) { return(-3); } var returnStatus = db.StorageProviderTypes.Add(storageProviderTypeEntity); db.SaveChanges(); var requirements = new List <StorageProviderRequirementObject>(); if (storageProviderType.StorageProviderRequirementObjects != null) { requirements = storageProviderType.StorageProviderRequirementObjects.ToList(); } if (requirements.Any()) { requirements.ToList().ForEach(k => { if (db.StorageProviderRequirements.Count(m => m.StorageProviderTypeId == storageProviderType.Id && m.DocumentTypeId == k.DocumentTypeId) < 1) { k.StorageProviderTypeId = returnStatus.Id; var storageProviderTypeReqEntity = ModelMapper.Map <StorageProviderRequirementObject, StorageProviderRequirement>(k); if (storageProviderTypeReqEntity != null && storageProviderTypeReqEntity.DocumentTypeId > 0 && storageProviderTypeReqEntity.StorageProviderTypeId > 0) { db.StorageProviderRequirements.Add(storageProviderTypeReqEntity); db.SaveChanges(); } } }); } return(returnStatus.Id); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long AddProductBankerDocument(DocumentObject document) { try { if (document == null) { return(-2); } var documentEntity = ModelMapper.Map <DocumentObject, Document>(document); if (documentEntity == null || string.IsNullOrEmpty(documentEntity.DocumentPath)) { return(-2); } using (var db = new ImportPermitEntities()) { var productBankers = db.ProductBankers.Where(b => b.ApplicationItemId == document.ApplicationItemId && b.BankId == document.BankId).ToList(); if (!productBankers.Any()) { return(-2); } var imApp = db.Documents.Add(documentEntity); db.SaveChanges(); var bankerEntity = productBankers[0]; bankerEntity.DocumentId = imApp.DocumentId; db.Entry(bankerEntity).State = EntityState.Modified; db.SaveChanges(); var app = new ApplicationDocument { DocumentId = imApp.DocumentId, ApplicationId = document.ApplicationId }; var dx = db.ApplicationDocuments.Add(app); db.SaveChanges(); if (dx.ApplicationDocumentId < 1) { db.Documents.Remove(imApp); return(0); } return(imApp.DocumentId); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long ProcessCompanyAddresses(List <CompanyAddressObject> addresses, long importerId) { try { if (!addresses.Any()) { return(-2); } using (var db = new ImportPermitEntities()) { var count = 0; addresses.ForEach(i => { var newAdd = new Address { AddressLine1 = i.AddressLine1, AddressLine2 = i.AddressLine2, CityId = i.CityId, LastUpdated = DateTime.Now.ToString("yyyy/MM/dddd") }; var addInfo = db.Addresses.Add(newAdd); db.SaveChanges(); var cmAdd = new ImporterAddress { AddressId = addInfo.AddressId, AddressTypeId = i.AddressTypeId, ImporterId = importerId, LastUpdated = DateTime.Now.ToString("yyyy/MM/dddd") }; db.ImporterAddresses.Add(cmAdd); db.SaveChanges(); count++; }); return(count == addresses.Count() ? 5 : -1); } } catch (DbEntityValidationException e) { var str = ""; foreach (var eve in e.EntityValidationErrors) { str += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State) + "\n"; str = eve.ValidationErrors.Aggregate(str, (current, ve) => current + (string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage) + " \n")); } ErrorLogger.LoggError(e.StackTrace, e.Source, str); return(0); } }
public long UpdateFormM(FormMDetailObject formM) { try { if (formM == null) { return(-2); } var formMEntity = ModelMapper.Map <FormMDetailObject, FormMDetail>(formM); if (formMEntity == null) { return(-2); } using (var db = new ImportPermitEntities()) { var oldFormMs = db.FormMDetails.Where(v => v.Id == formM.Id).ToList(); if (!oldFormMs.Any()) { return(-2); } var docs = db.Documents.Where(v => v.DocumentId == formM.AttachedDocumentId).ToList(); if (!docs.Any()) { return(-2); } var doc = docs[0]; if (doc.DocumentPath != formM.DocumentPath) { doc.DocumentPath = formM.DocumentPath; doc.DateUploaded = formM.DateAttached; db.Entry(doc).State = EntityState.Modified; db.SaveChanges(); } var formMDetail = oldFormMs[0]; formMDetail.FormMReference = formM.FormMReference; formMDetail.Quantity = formM.Quantity; formMDetail.LetterOfCreditNo = formM.LetterOfCreditNo; formMDetail.AttachedDocumentId = formM.AttachedDocumentId; formMDetail.DateAttached = formM.DateAttached; db.Entry(formMEntity).State = EntityState.Modified; db.SaveChanges(); return(formMEntity.Id); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long AddImporterDepotAndPerson(UserProfileObject person) { try { if (person == null) { return(-2); } using (var db = new ImportPermitEntities()) { var importer = new Importer { Name = person.CompanyName, IsActive = true, DateAdded = DateTime.Now.ToString("yyyy/MM/dd") }; var returnStatus = db.Importers.Add(importer); db.SaveChanges(); var prs = new Person { FirstName = person.FirstName, LastName = person.LastName, ImporterId = returnStatus.Id, IsAdmin = true, IsImporter = false, }; var depotEntity = new Depot { Name = importer.Name, ImporterId = returnStatus.Id, JettyId = person.JettyId }; db.Depots.Add(depotEntity); db.SaveChanges(); var prsId = db.People.Add(prs); db.SaveChanges(); return(prsId.Id); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public ActionResult Create([Bind(Include = "Id,IssueTypeId,ApplicationId,Description,Status,IssueDate,AmendedDate")] ApplicationIssue applicationissue) { if (ModelState.IsValid) { db.ApplicationIssues.Add(applicationissue); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ApplicationId = new SelectList(db.Applications, "ApplicationId", "ReferenceCode", applicationissue.ApplicationId); ViewBag.IssueTypeId = new SelectList(db.IssueTypes, "Id", "Description", applicationissue.IssueTypeId); return(View(applicationissue)); }
public long UpdateThroughPut(ThroughPutObject throughPut) { try { if (throughPut == null) { return(-2); } using (var db = new ImportPermitEntities()) { if (throughPut.DocumentObject != null && throughPut.DocumentObject.DocumentId > 0) { var documentEntities = db.Documents.Where(th => th.DocumentId == throughPut.DocumentObject.DocumentId).ToList(); if (!documentEntities.Any()) { return(-2); } var documentEntity = documentEntities[0]; documentEntity.UploadedById = throughPut.DocumentObject.UploadedById; documentEntity.IpAddress = throughPut.DocumentObject.IpAddress; documentEntity.Status = (int)AppStatus.Pending; documentEntity.DateUploaded = DateTime.Now; documentEntity.DocumentPath = throughPut.DocumentObject.DocumentPath; db.Entry(documentEntity).State = EntityState.Modified; db.SaveChanges(); } var throughPutEntities = db.ThroughPuts.Where(th => th.Id == throughPut.Id).ToList(); if (!throughPutEntities.Any()) { return(-2); } var throughPutEntity = throughPutEntities[0]; throughPutEntity.Quantity = throughPut.Quantity; throughPutEntity.IPAddress = throughPut.IPAddress; db.Entry(throughPutEntity).State = EntityState.Modified; db.SaveChanges(); return(throughPutEntity.Id); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long AddFormM(FormMDetailObject formM) { try { if (formM == null) { return(-2); } var formMEntity = ModelMapper.Map <FormMDetailObject, FormMDetail>(formM); if (formMEntity == null) { return(-2); } using (var db = new ImportPermitEntities()) { var documentEntity = ModelMapper.Map <DocumentObject, Document>(formM.DocumentObject); if (string.IsNullOrEmpty(documentEntity.DocumentPath)) { return(-2); } var ntDoc = db.Documents.Add(documentEntity); db.SaveChanges(); var app = new NotificationDocument { DocumentId = ntDoc.DocumentId, NotificationId = formM.DocumentObject.NotificationId, DateAttached = formM.DocumentObject.DateUploaded, Comment = formM.DocumentObject.Comment }; db.NotificationDocuments.Add(app); db.SaveChanges(); formMEntity.AttachedDocumentId = ntDoc.DocumentId; var imApp = db.FormMDetails.Add(formMEntity); db.SaveChanges(); return(imApp.Id); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long UpdateApplicationItem(ApplicationItemObject importItem) { try { if (importItem == null) { return(-2); } var importItemEntity = ModelMapper.Map <ApplicationItemObject, ApplicationItem>(importItem); if (importItemEntity == null || importItemEntity.Id < 1) { return(-2); } using (var db = new ImportPermitEntities()) { db.ApplicationItems.Attach(importItemEntity); db.Entry(importItemEntity).State = EntityState.Modified; db.SaveChanges(); return(importItem.Id); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long AddApplicationItem(ApplicationItemObject importItem) { try { if (importItem == null) { return(-2); } var importItemEntity = ModelMapper.Map <ApplicationItemObject, ApplicationItem>(importItem); if (importItemEntity == null || importItemEntity.ApplicationId < 1) { return(-2); } using (var db = new ImportPermitEntities()) { var returnStatus = db.ApplicationItems.Add(importItemEntity); db.SaveChanges(); return(returnStatus.Id); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long UpdateUnitOfMeasurement(UnitOfMeasurementObject unitOfMeasurement) { try { if (unitOfMeasurement == null) { return(-2); } var unitOfMeasurementEntity = ModelMapper.Map <UnitOfMeasurementObject, UnitOfMeasurement>(unitOfMeasurement); if (unitOfMeasurementEntity == null || unitOfMeasurementEntity.Id < 1) { return(-2); } using (var db = new ImportPermitEntities()) { db.UnitOfMeasurements.Attach(unitOfMeasurementEntity); db.Entry(unitOfMeasurementEntity).State = EntityState.Modified; db.SaveChanges(); return(unitOfMeasurement.Id); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long AddUnitOfMeasurement(UnitOfMeasurementObject unitOfMeasurement) { try { if (unitOfMeasurement == null) { return(-2); } var unitOfMeasurementEntity = ModelMapper.Map <UnitOfMeasurementObject, UnitOfMeasurement>(unitOfMeasurement); if (unitOfMeasurementEntity == null || string.IsNullOrEmpty(unitOfMeasurementEntity.Name)) { return(-2); } using (var db = new ImportPermitEntities()) { var returnStatus = db.UnitOfMeasurements.Add(unitOfMeasurementEntity); db.SaveChanges(); return(returnStatus.Id); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long UpdateImportApplicationHistory(ImportApplicationHistoryObject importApplicationHistory) { try { if (importApplicationHistory == null) { return(-2); } var importApplicationHistoryEntity = ModelMapper.Map <ImportApplicationHistoryObject, ImportApplicationHistory>(importApplicationHistory); if (importApplicationHistoryEntity == null || importApplicationHistoryEntity.Id < 1) { return(-2); } using (var db = new ImportPermitEntities()) { db.ImportApplicationHistories.Attach(importApplicationHistoryEntity); db.Entry(importApplicationHistoryEntity).State = EntityState.Modified; db.SaveChanges(); return(importApplicationHistory.Id); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long UpdateProductColumn(ProductColumnObject productColumn) { try { if (productColumn == null) { return(-2); } using (var db = new ImportPermitEntities()) { if (db.ProductColumns.Count(k => k.CustomCodeId == productColumn.CustomCodeId && k.ProductId == productColumn.ProductId && k.ProductColumnId != productColumn.ProductColumnId) > 0) { return(-3); } var productColumnEntity = ModelMapper.Map <ProductColumnObject, ProductColumn>(productColumn); if (productColumnEntity == null || productColumnEntity.ProductColumnId < 1) { return(-2); } db.ProductColumns.Attach(productColumnEntity); db.Entry(productColumnEntity).State = EntityState.Modified; db.SaveChanges(); return(productColumn.ProductColumnId); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long UpdateIssue(IssueObject issue) { try { if (issue == null) { return(-2); } var issueEntity = ModelMapper.Map <IssueObject, Issue>(issue); if (issueEntity == null || issueEntity.Id < 1) { return(-2); } using (var db = new ImportPermitEntities()) { db.Issues.Attach(issueEntity); db.Entry(issueEntity).State = EntityState.Modified; db.SaveChanges(); return(issue.Id); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long UpdateInvoiceItem(InvoiceItemObject fee) { try { if (fee == null) { return(-2); } var invoiceItemEntity = ModelMapper.Map <InvoiceItemObject, InvoiceItem>(fee); if (invoiceItemEntity == null || invoiceItemEntity.Id < 1) { return(-2); } using (var db = new ImportPermitEntities()) { db.InvoiceItems.Attach(invoiceItemEntity); db.Entry(invoiceItemEntity).State = EntityState.Modified; db.SaveChanges(); return(fee.Id); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long DeleteApplicationItems(long applicationId) { try { using (var db = new ImportPermitEntities()) { var myItems = db.ApplicationItems.Where(m => m.ApplicationId == applicationId).ToList(); if (!myItems.Any()) { return(0); } myItems.ForEach(item => { db.ApplicationItems.Remove(item); db.SaveChanges(); }); return(5); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long AddApplicationItems(List <ApplicationItemObject> importItems, long applicationId) { try { if (!importItems.Any()) { return(-2); } var successCount = 0; using (var db = new ImportPermitEntities()) { importItems.ForEach(importItem => { importItem.ApplicationId = applicationId; var importItemEntity = ModelMapper.Map <ApplicationItemObject, ApplicationItem>(importItem); if (importItemEntity != null && importItemEntity.ApplicationId > 0) { db.ApplicationItems.Add(importItemEntity); db.SaveChanges(); successCount += 1; } }); return(successCount); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long AddCustomCode(CustomCodeObject customCode) { try { if (customCode == null) { return(-2); } using (var db = new ImportPermitEntities()) { if (db.CustomCodes.Count(k => k.Name.ToLower().Trim() == customCode.Name.ToLower().Trim()) > 0) { return(-3); } var customCodeEntity = ModelMapper.Map <CustomCodeObject, CustomCode>(customCode); if (customCodeEntity == null || string.IsNullOrEmpty(customCodeEntity.Name)) { return(-2); } var returnStatus = db.CustomCodes.Add(customCodeEntity); db.SaveChanges(); return(returnStatus.CustomCodeId); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long AddInvoiceItem(InvoiceItemObject fee) { try { if (fee == null) { return(-2); } var invoiceItemEntity = ModelMapper.Map <InvoiceItemObject, InvoiceItem>(fee); if (invoiceItemEntity == null || invoiceItemEntity.InvoiceId < 1) { return(-2); } using (var db = new ImportPermitEntities()) { var returnStatus = db.InvoiceItems.Add(invoiceItemEntity); db.SaveChanges(); return(returnStatus.Id); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long UpdateCustomCode(CustomCodeObject customCode) { try { if (customCode == null) { return(-2); } using (var db = new ImportPermitEntities()) { if (db.CustomCodes.Count(k => k.Name.ToLower().Trim() == customCode.Name.ToLower().Trim() && k.CustomCodeId == customCode.CustomCodeId) > 0) { return(-3); } var customCodeEntity = ModelMapper.Map <CustomCodeObject, CustomCode>(customCode); if (customCodeEntity == null || customCodeEntity.CustomCodeId < 1) { return(-2); } db.CustomCodes.Attach(customCodeEntity); db.Entry(customCodeEntity).State = EntityState.Modified; db.SaveChanges(); return(customCode.CustomCodeId); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long UpdateRecertification(RecertificationObject recertification) { try { if (recertification == null) { return(-2); } var recertificationEntity = ModelMapper.Map <RecertificationObject, Recertification>(recertification); if (recertificationEntity == null || recertificationEntity.Id < 1) { return(-2); } using (var db = new ImportPermitEntities()) { db.Recertifications.Attach(recertificationEntity); db.Entry(recertificationEntity).State = EntityState.Modified; db.SaveChanges(); return(recertification.Id); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long AddAccountType(AccountTypeObject accountType) { try { if (accountType == null) { return(-2); } using (var db = new ImportPermitEntities()) { if (db.AccountTypes.Count(g => g.Name.ToLower().Trim().Replace(" ", "") == accountType.Name.ToLower().Trim().Replace(" ", "")) > 0) { return(-3); } var accountTypeEntity = ModelMapper.Map <AccountTypeObject, AccountType>(accountType); if (accountTypeEntity == null || string.IsNullOrEmpty(accountTypeEntity.Name)) { return(-2); } var returnStatus = db.AccountTypes.Add(accountTypeEntity); db.SaveChanges(); return(returnStatus.AccountTypeId); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long DeleteEmployeeDesk(long employeeDeskId) { try { using (var db = new ImportPermitEntities()) { var myItems = db.EmployeeDesks.Where(m => m.Id == employeeDeskId).ToList(); if (!myItems.Any()) { return(0); } var item = myItems[0]; db.EmployeeDesks.Remove(item); db.SaveChanges(); return(5); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long UpdateAccountType(AccountTypeObject accountType) { try { if (accountType == null) { return(-2); } using (var db = new ImportPermitEntities()) { if (db.AccountTypes.Count(g => g.Name.ToLower().Trim().Replace(" ", "") == accountType.Name.ToLower().Trim().Replace(" ", "") && g.AccountTypeId != accountType.AccountTypeId) > 0) { return(-3); } var accountTypeEntity = ModelMapper.Map <AccountTypeObject, AccountType>(accountType); if (accountTypeEntity == null || accountTypeEntity.AccountTypeId < 1) { return(-2); } db.AccountTypes.Attach(accountTypeEntity); db.Entry(accountTypeEntity).State = EntityState.Modified; db.SaveChanges(); return(accountType.AccountTypeId); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }