public void Delete(T entity) { try { using (var context = new CTDSContext()) { var DbSet = context.Set <T>(); DbSet.Remove(entity); context.SaveChanges(); } } catch (Exception exception) { throw exception; } }
public void DeleteRange(IEnumerable <T> entityList) { try { using (var context = new CTDSContext()) { var DbSet = context.Set <T>(); DbSet.RemoveRange(entityList); context.SaveChanges(); } } catch (Exception exception) { throw exception; } }
public void AddReference(ReferenceDto reference) { try { using (var context = new CTDSContext()) { var data = Mapper.DtoToReferenceModel(reference); context.Reference.AddOrUpdate(d => d.ReferenceId, data); context.SaveChanges(); } } catch (Exception) { throw; } }
public T Add(T entity) { entity.ModifiedOn = DateTime.Now; entity.CreatedOn = DateTime.Now; try { using (var context = new CTDSContext()) { var DbSet = context.Set <T>(); DbSet.Add(entity); context.SaveChanges(); return(entity); } } catch (Exception exception) { throw exception; } }
public bool SendToCustom(DeclarationDto declarationDto) { bool result = false; try { using (var context = new CTDSContext()) { var declaration = Mapper.DtoToDeclaration(declarationDto); context.Declaration.AddOrUpdate(declaration); context.SaveChanges(); result = true; } return(result); } catch (Exception) { throw; } }
public void CreateCases(int numberOfCasesToSeed) { for (int index = 0; index < numberOfCasesToSeed; ++index) { Case @case = new Case(); Guid gId = Guid.NewGuid(); @case.Id = gId; @case.CreatedOn = CreateRandomDate(3); @case.ModifiedOn = CreateRandomDate(3); CTDSContext.Case.Add(@case); CTDSContext.Client.Add(CreateClient(gId, index)); CTDSContext.CaseInformation.Add(CreateCaseInformation(gId)); CTDSContext.CaseStatus.Add(CreateCaseStatus(gId)); CTDSContext.Notes.Add(CreateNotes(gId)); } CTDSContext.SaveChanges(); Console.WriteLine("Data Created"); }
public void AddRange(IEnumerable <T> entityList) { foreach (var item in entityList) { item.CreatedOn = DateTime.Now; item.ModifiedOn = DateTime.Now; } try { using (var context = new CTDSContext()) { var DbSet = context.Set <T>(); DbSet.AddRange(entityList); context.SaveChanges(); } } catch (Exception exception) { throw exception; } }
public Guid AddDeclaration(DeclarationDto declarationDto) { Guid success; try { using (var context = new CTDSContext()) { var declaration = Mapper.DtoToDeclaration(declarationDto); var newDeclaration = context.Declaration.Add(declaration); context.SaveChanges(); success = newDeclaration.DeclarationId; } return(success); } catch (Exception) { throw; } }
public bool EditDeclaration(DeclarationDto declarationDto) { bool response; try { using (var context = new CTDSContext()) { //_context.Declaration.Log = s => { System.Diagnostics.Debug.WriteLine(s); }; var declaration = Mapper.DtoToDeclaration(declarationDto); context.Declaration.AddOrUpdate(declaration); context.SaveChanges(); response = true; } return(response); } catch (Exception) { throw; } }
public T Update(T entity) { try { using (var context = new CTDSContext()) { var DbSet = context.Set <T>(); entity.ModifiedOn = DateTime.Now; if (entity.CreatedOn == DateTime.MinValue) { entity.CreatedOn = DateTime.Now; } DbSet.AddOrUpdate(entity); context.SaveChanges(); return(entity); } } catch (Exception exception) { throw exception; } }
public void CreateDeclarations(int numberOfDeclarations) { var countries = CTDSContext.MasterData.Where(d => d.Type == "Countries").ToList(); var termsOfDelivery = CTDSContext.MasterData.Where(d => d.Type == "TermsOfDelivery").ToList(); var modesOfTransport = CTDSContext.MasterData.Where(d => d.Type == "ModeOfTransport").ToList(); var locationsOfGoods = CTDSContext.MasterData.Where(d => d.Type == "LocationOfGoods").ToList(); var naturesOfTransaction = CTDSContext.MasterData.Where(d => d.Type == "NatureOfTransaction").ToList(); var referenceTypes = CTDSContext.MasterData.Where(d => d.Type == "ReferenceType").ToList(); var messsageNames = CTDSContext.MasterData.Where(d => d.Type == "MessageName").ToList(); var declaratationTypes1 = CTDSContext.MasterData.Where(d => d.Type == "DeclarationType1").ToList(); var declarationTypes2 = CTDSContext.MasterData.Where(d => d.Type == "DeclarationType2").ToList(); var defferedPayments = CTDSContext.MasterData.Where(d => d.Type == "DefferedPayment").ToList(); var supervisingCustomOfiice = CTDSContext.MasterData.Where(d => d.Type == "SupervisingCustomOfiice").ToList(); for (int index = 0; index < numberOfDeclarations; ++index) { int rnd = Random.Next(); Declaration declaration = new Declaration(); declaration.MessageName = messsageNames[Random.Next(messsageNames.Count)].Key; declaration.DeclarationType1 = declaratationTypes1[Random.Next(declaratationTypes1.Count)].Key; declaration.DeclarationType2 = declarationTypes2[Random.Next(declarationTypes2.Count)].Key; declaration.ConsignorName = "ConsignorName" + index; declaration.ConsignorAddress1 = "ConsignorAddressOne" + index; declaration.ConsignorAddress2 = "ConsignorAddressTwo" + index; declaration.ConsignorCity = "ConsignorCity" + index; declaration.ConsignorPostalCode = rnd.ToString(); declaration.ConsignorCountry = countries[Random.Next(countries.Count)].Key; declaration.ConsigneeOrganisationNumber = "ConsigneeOrg" + index; declaration.ConsigneeName = "ConsigneeName" + index; declaration.ConsigneeAddress2 = "ConsigneeAddressTwo" + index; declaration.ConsigneeAddress1 = "ConsigneeAddressOne" + index; declaration.ConsigneePostalCode = rnd.ToString(); declaration.ConsigneeCity = "ConsigneeCity" + index; declaration.ConsigneeCountry = countries[Random.Next(countries.Count)].Key; declaration.CustomCreditNumber = rnd.ToString(); declaration.DefferedPayment = defferedPayments[Random.Next(defferedPayments.Count)].Key; declaration.DeclarantOrganisationNumber = "DeclarantOrgNumber" + index; declaration.DeclarantName = "DeclarantName" + index; declaration.DeclarantAddress2 = "DeclarantAddressTwo" + index; declaration.DeclarantAddress1 = "DeclarantAddressOne" + index; declaration.DeclarantPostalCode = rnd.ToString(); declaration.DeclarantCity = "DeclarantCity" + index; declaration.DeclarantCountry = countries[Random.Next(countries.Count)].Key; declaration.ContactPerson = rnd.ToString(); declaration.TermsOfDelivery = termsOfDelivery[Random.Next(termsOfDelivery.Count)].Key; declaration.DeliveryPlace = "DelPlace" + index; declaration.CountryOfDispatch = countries[Random.Next(countries.Count)].Key; declaration.NationalityOfTransport = countries[Random.Next(countries.Count)].Key; declaration.ModeOfTransport = modesOfTransport[Random.Next(modesOfTransport.Count)].Key; declaration.LocationOfGoods = locationsOfGoods[Random.Next(locationsOfGoods.Count)].Key; declaration.SupervisingCustomOffice = supervisingCustomOfiice[Random.Next(supervisingCustomOfiice.Count)].Key; declaration.Freight = "Freight"; declaration.Amount = rnd.ToString(); declaration.Currency = Random.Next(1, 4).ToString(); declaration.Rate = Random.Next().ToString(); declaration.CreatedOn = CreateRandomDate(1); List <string> statusTypes = new List <string>() { "Processing", "Rejected", "Cleared" }; declaration.Status = statusTypes[Random.Next(statusTypes.Count())]; //declaration. CTDSContext.Declaration.Add(declaration); } CTDSContext.SaveChanges(); }