public async Task RequiresTwoSetsOfOneOfTwoSignaturesToTransferOut() { var initialBalance = (ulong)Generator.Integer(10, 200); var(publicKey1a, privateKey1a) = Generator.KeyPair(); var(publicKey1b, privateKey1b) = Generator.KeyPair(); var(publicKey2a, privateKey2a) = Generator.KeyPair(); var(publicKey2b, privateKey2b) = Generator.KeyPair(); var endorsement = new Endorsement(new Endorsement(1, publicKey1a, publicKey1b), new Endorsement(1, publicKey2a, publicKey2b)); var client = _network.NewClient(); var createResult = await client.CreateAccountAsync(new CreateAccountParams { InitialBalance = initialBalance, Endorsement = endorsement }); Assert.Equal(ResponseCode.Success, createResult.Status); // Fail by not providing all necessary keys (note only one of the root keys here) var from = createResult.Address; var tex = await Assert.ThrowsAsync <TransactionException>(async() => { await client.TransferWithRecordAsync(from, _network.Payer, (long)initialBalance, privateKey1a); }); Assert.Equal(ResponseCode.InvalidSignature, tex.Status); // Now try with proper set of signatures from = createResult.Address; var record = await client.TransferWithRecordAsync(from, _network.Payer, (long)initialBalance, new Signatory(privateKey1b, privateKey2a)); var balance = await client.GetAccountBalanceAsync(createResult.Address); Assert.Equal(0UL, balance); }
internal Key(Endorsement endorsement) : this() { switch (endorsement.Type) { case KeyType.Ed25519: Ed25519 = ByteString.CopyFrom(((Ed25519PublicKeyParameters)endorsement._data).GetEncoded()); break; case KeyType.RSA3072: RSA3072 = ByteString.CopyFrom(((ReadOnlyMemory <byte>)endorsement._data).ToArray()); break; case KeyType.ECDSA384: ECDSA384 = ByteString.CopyFrom(((ReadOnlyMemory <byte>)endorsement._data).ToArray()); break; case KeyType.Contract: ContractID = new ContractID((Address)Abi.DecodeAddressPart((ReadOnlyMemory <byte>)endorsement._data)); break; case KeyType.List: ThresholdKey = new ThresholdKey { Threshold = endorsement.RequiredCount, Keys = new KeyList((Endorsement[])endorsement._data) }; break; default: throw new InvalidOperationException("Endorsement is Empty."); } }
public async Task ChangeKeyToRequiresTwoSetsOfOneOfTwoSignaturesToTransferOut() { await using var fx = await TestAccount.CreateAsync(_network); var(publicKey1a, privateKey1a) = Generator.KeyPair(); var(publicKey1b, privateKey1b) = Generator.KeyPair(); var(publicKey2a, privateKey2a) = Generator.KeyPair(); var(publicKey2b, privateKey2b) = Generator.KeyPair(); var endorsement = new Endorsement(new Endorsement(1, publicKey1a, publicKey1b), new Endorsement(1, publicKey2a, publicKey2b)); var receipt = await fx.Client.UpdateAccountAsync(new UpdateAccountParams { Address = fx.Record.Address, Endorsement = endorsement, Signatory = new Signatory(fx.PrivateKey, privateKey1a, privateKey1b, privateKey2a, privateKey2b) }); Assert.Equal(ResponseCode.Success, receipt.Status); // Fail by not providing all necessary keys (note only one of the root keys here) var tex = await Assert.ThrowsAsync <TransactionException>(async() => { await fx.Client.TransferWithRecordAsync(fx.Record.Address, _network.Payer, (long)fx.CreateParams.InitialBalance, fx.PrivateKey); }); Assert.Equal(ResponseCode.InvalidSignature, tex.Status); // Now try with proper set of signatures var record = await fx.Client.TransferWithRecordAsync(fx.Record.Address, _network.Payer, (long)fx.CreateParams.InitialBalance, new Signatory(privateKey1a, privateKey2b)); var balance = await fx.Client.GetAccountBalanceAsync(fx.Record.Address); Assert.Equal(0UL, balance); }
public static bool ValidateEndorsement(Endorsement endorsement) { bool isValidendorsement = true; StringBuilder sb = new StringBuilder(); if (endorsement.InsuredName == null || endorsement.InsuredAge == 0 || endorsement.Telephone == null || endorsement.Nominee == null || endorsement.Relation == null || endorsement.Address == null) { isValidendorsement = false; sb.Append("Endorsement Fields cannot be Null" + Environment.NewLine); } if (!(Regex.IsMatch(endorsement.Telephone, "[0-9]{10}"))) { isValidendorsement = false; sb.Append("Telephone Number should be of 10 Digits" + Environment.NewLine); } if (endorsement.Dob > DateTime.Now) { isValidendorsement = false; sb.Append("Date of Birth Should not be greater than today" + Environment.NewLine); } if (!isValidendorsement) { throw new PolicyException(sb.ToString()); } return(isValidendorsement); }
private async Task RemoveFromTree(Endorsement omit) { if (SwapEndorsementsInTree(Value, omit, null, out Endorsement revisedValue)) { await UpdateKeyValue(revisedValue); } }
public async Task CanUpdateMultiplePropertiesInOneCall() { await using var fx = await GreetingContract.CreateAsync(_network); var(newPublicKey, newPrivateKey) = Generator.KeyPair(); var newExpiration = Generator.TruncatedFutureDate(2400, 4800); var newEndorsement = new Endorsement(newPublicKey); var updatedSignatory = new Signatory(_network.Signatory, newPrivateKey); var newMemo = Generator.Code(50); fx.Client.Configure(ctx => ctx.Signatory = updatedSignatory); var record = await fx.Client.UpdateContractWithRecordAsync(new UpdateContractParams { Contract = fx.ContractRecord.Contract, Expiration = newExpiration, Administrator = newEndorsement, Memo = newMemo }); var info = await fx.Client.GetContractInfoAsync(fx.ContractRecord.Contract); Assert.NotNull(info); Assert.Equal(fx.ContractRecord.Contract, info.Contract); Assert.Equal(fx.ContractRecord.Contract, info.Address); Assert.Equal(newExpiration, info.Expiration); Assert.Equal(newEndorsement, info.Administrator); Assert.Equal(fx.ContractParams.RenewPeriod, info.RenewPeriod); Assert.Equal(newMemo, info.Memo); Assert.Equal((ulong)fx.ContractParams.InitialBalance, info.Balance); }
public HttpResponseMessage Post([FromBody] EndorseModel model) { try { var identity = (ClaimsIdentity)User.Identity; var claims = identity.Claims.Select(x => new { type = x.Type, value = x.Value }); string userId = claims.Where(a => a.type == "UserId").Select(a => a.value).SingleOrDefault().ToString();; model.NGOId = string.IsNullOrEmpty(userId) ? 0 : Convert.ToInt32(userId); if (IService.ISUserNGO(model.NGOId)) { Endorsement returnmodel = IService.PostEndorsements(model); return(Request.CreateResponse(HttpStatusCode.OK, returnmodel)); } else { ResponseObject response = new ResponseObject(); response.ExceptionMsg = "You Are not Authorized NGO"; response.ResponseMsg = "You Are not Authorized NGO"; response.ErrorCode = HttpStatusCode.InternalServerError.ToString(); return(Request.CreateResponse(HttpStatusCode.Conflict, response)); } } catch (Exception ex) { ResponseObject response = new ResponseObject(); response.ExceptionMsg = ex.InnerException != null?ex.InnerException.ToString() : ex.Message; response.ResponseMsg = "Could not Post the details of Endorse"; response.ErrorCode = HttpStatusCode.InternalServerError.ToString(); return(Request.CreateResponse(HttpStatusCode.InternalServerError, response)); } }
internal static Key ToPublicKey(Endorsement endorsement) { switch (endorsement.Type) { case KeyType.Ed25519: return(new Key { Ed25519 = ByteString.CopyFrom(((NSec.Cryptography.PublicKey)endorsement._data).Export(NSec.Cryptography.KeyBlobFormat.PkixPublicKey).TakeLast(32).ToArray()) }); case KeyType.RSA3072: return(new Key { RSA3072 = ByteString.CopyFrom(((ReadOnlyMemory <byte>)endorsement._data).ToArray()) }); case KeyType.ECDSA384: return(new Key { ECDSA384 = ByteString.CopyFrom(((ReadOnlyMemory <byte>)endorsement._data).ToArray()) }); case KeyType.List: return(new Key { ThresholdKey = new ThresholdKey { Threshold = endorsement.RequiredCount, Keys = ToPublicKeyList((Endorsement[])endorsement._data) } }); } throw new InvalidOperationException("Endorsement is Empty."); }
public static List <Endorsement> GetEndorsements(string licenceId, IDynamicsClient dynamicsClient) { List <Endorsement> endorsementsList = new List <Endorsement>(); string filter = $"_adoxio_licence_value eq {licenceId}"; string[] expand = { "adoxio_ApplicationType" }; MicrosoftDynamicsCRMadoxioEndorsementCollection endorsementsCollection = dynamicsClient.Endorsements.Get(filter: filter, expand: expand); if (endorsementsCollection.Value.Count > 0) { foreach (var item in endorsementsCollection.Value) { if (item.AdoxioApplicationType != null) { Endorsement endorsement = new Endorsement() { Id = item.AdoxioApplicationType.AdoxioApplicationtypeid, Name = item.AdoxioApplicationType.AdoxioName }; endorsementsList.Add(endorsement); } } } return(endorsementsList); }
public IHttpActionResult PutEndorsement(int id, Endorsement endorsement) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != endorsement.Id) { return(BadRequest()); } db.Entry(endorsement).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!EndorsementExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public EndorsementCheckResult CheckList(BillOfExchange billOfExchange, IEnumerable <Endorsement> endorsemetList) { if (endorsemetList.Any(e => e.BillId != billOfExchange.Id)) { throw new ArgumentException($"There is record in {nameof(endorsemetList)} which is not connected to {nameof(billOfExchange)}"); } if (!endorsemetList.Any()) { return(new EndorsementCheckResult(true)); } var first = endorsemetList.Where(e => e.PreviousEndorsementId == null).ToList(); if (first.Count == 0) { return(new EndorsementCheckResult(false, "There is no first endorsement")); } if (first.Count > 1) { return(new EndorsementCheckResult(false, "There is too many starting endorsement", first)); } Endorsement current = first.First(); if (current.NewBeneficiaryId == billOfExchange.BeneficiaryId) { return(new EndorsementCheckResult(false, $"Endorsement with id {current.Id} have same BeneficiaryId {current.NewBeneficiaryId} as billOfExchange.", current)); } ISet <int> usedIds = new HashSet <int>(); usedIds.Add(current.Id); do { Endorsement next = endorsemetList.FirstOrDefault(e => current.Id == e.PreviousEndorsementId); if (next is null) { break; } if (next.NewBeneficiaryId == current.NewBeneficiaryId) { return(new EndorsementCheckResult(false, $"There is same BeneficiaryId {next.NewBeneficiaryId} in two endorsement ids {current.Id} and {next.Id}", current, next)); } if (usedIds.Contains(next.Id)) { return(new EndorsementCheckResult(false, $"Endorsement with id {next.Id} is used.", next)); } usedIds.Add(next.Id); current = next; } while (true); if (usedIds.Count != endorsemetList.Count()) { return(new EndorsementCheckResult(false, "Tehere is endorsement in endrosementList which is not in the sequence.", endorsemetList.Where(e => !usedIds.Contains(e.Id)).ToArray())); } return(new EndorsementCheckResult(true)); }
private static bool SwapEndorsementsInTree(Endorsement original, Endorsement toRemove, Endorsement toAdd, out Endorsement revisedValue) { if (original != null) { if (original.Equals(toRemove)) { revisedValue = toAdd; return(true); } else if (original.Type == KeyType.List) { var copy = original.List.ToArray(); for (int i = 0; i < copy.Length; i++) { if (SwapEndorsementsInTree(copy[i], toRemove, toAdd, out Endorsement revisedChild)) { copy[i] = revisedChild; copy = copy.Where(e => e != null).ToArray(); var required = (uint)Math.Min(copy.Length, original.RequiredCount); revisedValue = copy.Length > 0 ? new Endorsement(required, copy) : null; return(true); } } } } else if (toAdd != null) { revisedValue = toAdd; return(true); } revisedValue = original; return(false); }
public async Task CanUpdateMultiplePropertiesInOneCall() { await using var fx = await GreetingContract.CreateAsync(_network); var(newPublicKey, newPrivateKey) = Generator.KeyPair(); var newExpiration = Generator.TruncatedFutureDate(2400, 4800); var newEndorsement = new Endorsement(newPublicKey); var newRenewal = TimeSpan.FromDays(Generator.Integer(60, 90)); var updatedPayer = _network.PayerWithKeys(newPrivateKey); var newMemo = Generator.Code(50); fx.Client.Configure(ctx => ctx.Payer = updatedPayer); var record = await fx.Client.UpdateContractWithRecordAsync(new UpdateContractParams { Contract = fx.ContractRecord.Contract, Expiration = newExpiration, Administrator = newEndorsement, RenewPeriod = newRenewal, Memo = newMemo }); var info = await fx.Client.GetContractInfoAsync(fx.ContractRecord.Contract); Assert.NotNull(info); Assert.Equal(fx.ContractRecord.Contract, info.Contract); Assert.Equal(fx.ContractRecord.Contract, info.Address); //Assert.Equal(newExpiration, info.Expiration); Assert.Equal(newEndorsement, info.Administrator); Assert.Equal(newRenewal, info.RenewPeriod); Assert.Equal(newMemo, info.Memo); }
public void DisimilarMultiKeyEndorsementsAreNotConsideredEqual() { var(publicKey1, _) = Generator.Ed25519KeyPair(); var(publicKey2, _) = Generator.Ed25519KeyPair(); var(publicKey3, _) = Generator.Secp256k1KeyPair(); var endorsements1 = new Endorsement(publicKey1, publicKey2); var endorsements2 = new Endorsement(publicKey2, publicKey3); Assert.NotEqual(endorsements1, endorsements2); Assert.False(endorsements1 == endorsements2); Assert.True(endorsements1 != endorsements2); endorsements1 = new Endorsement(1, publicKey1, publicKey2); endorsements2 = new Endorsement(2, publicKey2, publicKey3); Assert.NotEqual(endorsements1, endorsements2); Assert.False(endorsements1 == endorsements2); Assert.True(endorsements1 != endorsements2); endorsements1 = new Endorsement(1, publicKey1, publicKey2, publicKey3); endorsements2 = new Endorsement(2, publicKey1, publicKey2, publicKey3); Assert.NotEqual(endorsements1, endorsements2); Assert.False(endorsements1 == endorsements2); Assert.True(endorsements1 != endorsements2); endorsements1 = new Endorsement(2, publicKey1, publicKey2, publicKey3); endorsements2 = new Endorsement(3, publicKey1, publicKey2, publicKey3); Assert.NotEqual(endorsements1, endorsements2); Assert.False(endorsements1 == endorsements2); Assert.True(endorsements1 != endorsements2); }
private void BuildRenderTreeForEndorsement(RenderTreeBuilder builder, Endorsement root) { builder.OpenComponent <InputEndorsement>(); builder.AddAttribute("Value", RuntimeHelpers.TypeCheck(root)); builder.AddAttribute("ValueChanged", RuntimeHelpers.TypeCheck(EventCallback.Factory.Create(this, RuntimeHelpers.CreateInferredEventCallback(this, __value => SwapRootEndorsment(root, __value), root)))); builder.CloseComponent(); }
public void DisimilarClaimHashesAreNotConsideredEqual() { var(publicKey1, _) = Generator.KeyPair(); var(publicKey2, _) = Generator.KeyPair(); var hash1 = new SHA384Managed().ComputeHash(Generator.KeyPair().publicKey.ToArray()); var hash2 = new SHA384Managed().ComputeHash(Generator.KeyPair().publicKey.ToArray()); var endorsements = new Endorsement[] { publicKey1, publicKey2 }; var duration = TimeSpan.FromDays(Generator.Integer(10, 20)); var address = new Address(0, 0, Generator.Integer(1000, 2000)); var claim1 = new Claim { Address = address, Hash = hash1, Endorsements = endorsements, ClaimDuration = duration }; var claim2 = new Claim { Address = address, Hash = hash2, Endorsements = endorsements, ClaimDuration = duration }; Assert.NotEqual(claim1, claim2); Assert.False(claim1 == claim2); Assert.True(claim1 != claim2); Assert.False(claim1.Equals(claim2)); Assert.NotEqual(claim2, claim1); Assert.False(claim2 == claim1); Assert.True(claim2 != claim1); Assert.False(claim2.Equals(claim1)); }
public bool AddEndorsementDAL(Endorsement endorsement) { bool recordAdded = false; try { entities.prcEndorsementInsert( endorsement.PolicyID, endorsement.ProductType, endorsement.ProductName, endorsement.InsuredName, endorsement.InsuredAge, endorsement.Dob, endorsement.Gender, endorsement.Nominee, endorsement.Relation, endorsement.Smoker, endorsement.Address, endorsement.Telephone, endorsement.PremiumFrequency); recordAdded = true; } catch (SqlException e) { throw new Exception(e.Message); } return(recordAdded); }
internal Key(Endorsement endorsement) : this() { switch (endorsement.Type) { case KeyType.Ed25519: Ed25519 = ByteString.CopyFrom(((Ed25519PublicKeyParameters)endorsement._data).GetEncoded()); break; case KeyType.ECDSASecp256K1: ECDSASecp256K1 = ByteString.CopyFrom(((ECPublicKeyParameters)endorsement._data).Q.GetEncoded(true)); break; case KeyType.Contract: ContractID = new ContractID((Address)endorsement._data); break; case KeyType.List: ThresholdKey = new ThresholdKey { Threshold = endorsement.RequiredCount, Keys = new KeyList((Endorsement[])endorsement._data) }; break; default: throw new InvalidOperationException("Endorsement is Empty."); } }
public void CanCreateEquivalentAliasWithDifferentConstructors() { var(publicKey, _) = Generator.KeyPair(); var endorsement = new Endorsement(publicKey); var alias1 = new Alias(publicKey); var alias2 = new Alias(endorsement); var alias3 = new Alias(0, 0, publicKey); var alias4 = new Alias(0, 0, endorsement); Assert.Equal(alias1, alias2); Assert.Equal(alias1, alias3); Assert.Equal(alias1, alias4); Assert.Equal(alias2, alias3); Assert.Equal(alias2, alias4); Assert.Equal(alias3, alias4); Assert.True(alias1 == alias2); Assert.True(alias1 == alias3); Assert.True(alias1 == alias4); Assert.True(alias2 == alias3); Assert.True(alias2 == alias4); Assert.True(alias3 == alias4); Assert.False(alias1 != alias2); Assert.False(alias1 != alias3); Assert.False(alias1 != alias4); Assert.False(alias2 != alias3); Assert.False(alias2 != alias4); Assert.False(alias3 != alias4); Assert.True(alias1.Equals(alias2)); Assert.True(alias1.Equals(alias3)); Assert.True(alias1.Equals(alias4)); Assert.True(alias2.Equals(alias3)); Assert.True(alias2.Equals(alias4)); Assert.True(alias3.Equals(alias4)); }
public bool EndorseUser(string endorsedUserId, string endorsedById, int skillId) { var endorsedUser = this.users.All().FirstOrDefault(x => x.Id == endorsedUserId); var endorsedBy = this.users.All().FirstOrDefault(x => x.Id == endorsedById); var skill = endorsedUser.Skills.FirstOrDefault(x => x.Id == skillId); var endorsement = new Endorsement { SkillId = skillId, EndorsedBy = endorsedBy }; endorsedUser.Updates.Add(new Update { ContentText = string.Format("{0} {1} endorsed {2} {3} for their {4} skill.", endorsedBy.FirstName, endorsedBy.LastName, endorsedUser.FirstName, endorsedUser.LastName, skill.Name) }); endorsedUser.Endorsements.Add(endorsement); this.users.Update(endorsedUser); this.users.SaveChanges(); return(true); }
private async Task AddNewKeyToTree(Endorsement parent) { var newKey = await InputPublicKeyDialog.PromptForPublicKey(); if (newKey != null) { if (parent == null) { await UpdateKeyValue(newKey); } else if (parent.Type == KeyType.List) { var newlist = parent.List.Append(newKey).ToArray(); var requiredCount = parent.List.Length == parent.RequiredCount ? (uint)newlist.Length : parent.RequiredCount; if (SwapEndorsementsInTree(Value, parent, new Endorsement(requiredCount, newlist), out Endorsement revisedValue)) { await UpdateKeyValue(revisedValue); } } else { // This shouldn't happen, but less bad than crashing or doing nothing. if (SwapEndorsementsInTree(Value, parent, new Endorsement(parent, newKey), out Endorsement revisedValue)) { await UpdateKeyValue(revisedValue); } } } }
private async Task ConvertToList(Endorsement key) { if (SwapEndorsementsInTree(Value, key, new Endorsement(key), out Endorsement revisedValue)) { await UpdateKeyValue(revisedValue); } }
public bool AddEndorsementDAL(Endorsement endorsement) { bool recordAdded = false; try { entities.Database.SqlQuery <PolicyEntities>("exec prcEndorsementInsert @policyID,@productType,@productName,@insuredName,@insuredAge,@dob,@gender,@nominee,@relation,@smoker,@address,@telephone,@premiumFrequency", new SqlParameter("@policyID", endorsement.PolicyID), new SqlParameter("@productType", endorsement.ProductType), new SqlParameter("@productName", endorsement.ProductName), new SqlParameter("@insuredName", endorsement.InsuredName), new SqlParameter("@insuredAge", endorsement.InsuredAge), new SqlParameter("@dob", endorsement.Dob), new SqlParameter("@gender", endorsement.Gender), new SqlParameter("@nominee", endorsement.Nominee), new SqlParameter("@relation", endorsement.Relation), new SqlParameter("@smoker", endorsement.Smoker), new SqlParameter("@address", endorsement.Address), new SqlParameter("@telephone", endorsement.Telephone), new SqlParameter("@premiumFrequency", endorsement.PremiumFrequency)); recordAdded = true; } catch (SqlException e) { throw new Exception(e.Message); } return(recordAdded); }
public async Task CanUpdateAdminKey() { await using var fx = await GreetingContract.CreateAsync(_network); var(newPublicKey, newPrivateKey) = Generator.KeyPair(); var newEndorsement = new Endorsement(newPublicKey); var updatedSignatory = new Signatory(_network.Signatory, newPrivateKey); fx.Client.Configure(ctx => ctx.Signatory = updatedSignatory); var record = await fx.Client.UpdateContractWithRecordAsync(new UpdateContractParams { Contract = fx.ContractRecord.Contract, Administrator = newEndorsement, }); var info = await fx.Client.GetContractInfoAsync(fx.ContractRecord.Contract); Assert.NotNull(info); Assert.Equal(fx.ContractRecord.Contract, info.Contract); Assert.Equal(fx.ContractRecord.Contract, info.Address); Assert.Equal(newEndorsement, info.Administrator); Assert.Equal(fx.ContractParams.RenewPeriod, info.RenewPeriod); Assert.Equal(fx.Memo, info.Memo); Assert.Equal((ulong)fx.ContractParams.InitialBalance, info.Balance); }
public ActionResult DeleteConfirmed(int id) { Endorsement endorsement = db.Endorsements.Find(id); db.Endorsements.Remove(endorsement); db.SaveChanges(); return(RedirectToAction("Index")); }
public CheckListFixture AppendEndorsement(int newBeneficiaryId, int previousEndorsementId, bool isCorrect = true) { Endorsement endorsement = CreateEndorsement(newBeneficiaryId, EndorsementList.FirstOrDefault()?.Id, isCorrect); endorsement.PreviousEndorsementId = previousEndorsementId; EndorsementList.Add(endorsement); return(this); }
protected void gvExistingEndorsements_RowCommand(object sender, CommandEventArgs e) { if (e == null || String.IsNullOrEmpty(e.CommandArgument.ToString())) { return; } int id = Convert.ToInt32(e.CommandArgument, CultureInfo.InvariantCulture); try { if (id <= 0) { throw new MyFlightbookException("Invalid endorsement ID to delete"); } if (e.CommandName.CompareOrdinalIgnoreCase("_DeleteExternal") == 0 && !String.IsNullOrEmpty(e.CommandArgument.ToString())) { List <Endorsement> rgEndorsements = new List <Endorsement>(Endorsement.EndorsementsForUser(null, Page.User.Identity.Name)); Endorsement en = rgEndorsements.FirstOrDefault(en2 => en2.ID == id); if (en == null) { throw new MyFlightbookException("ID of endorsement to delete is not found in owners endorsements"); } if (en.StudentType == Endorsement.StudentTypes.Member) { throw new MyFlightbookException(Resources.SignOff.errCantDeleteMemberEndorsement); } en.FDelete(); RefreshEndorsements(); } else if (e.CommandName.CompareOrdinalIgnoreCase("_DeleteOwned") == 0 && !String.IsNullOrEmpty(e.CommandArgument.ToString())) { List <Endorsement> rgEndorsements = new List <Endorsement>(Endorsement.EndorsementsForUser(Page.User.Identity.Name, null)); Endorsement en = rgEndorsements.FirstOrDefault(en2 => en2.ID == id); if (en == null) { throw new MyFlightbookException("Can't find endorsement with ID=" + id.ToString()); } if (en.StudentType == Endorsement.StudentTypes.External) { throw new MyFlightbookException("Can't delete external endorsement with ID=" + id.ToString()); } en.FDelete(); RefreshEndorsements(); } } catch (MyFlightbookException ex) { lblErr.Text = ex.Message; } }
protected void gvExistingEndorsements_RowDataBound(object sender, GridViewRowEventArgs e) { if (e != null && e.Row.RowType == DataControlRowType.DataRow) { Endorsement endorsement = (Endorsement)e.Row.DataItem; Controls_mfbEndorsement mfbEndorsement = (Controls_mfbEndorsement)e.Row.FindControl("mfbEndorsement1"); mfbEndorsement.SetEndorsement(endorsement); } }
public ActionResult Edit([Bind(Include = "EndorsementID,Your_Name,Street_Address,City,State,Zip,Email_Address,Today_s_Date,Name_of_Recipient,Title,Company,Recipient_Address,Recipient_City,Recipient_State,Recipient_Zip,Salutation,Paragraph1,Paragraph2,Paragraph3,Paragraph4,Paragraph5,Closing,Titles")] Endorsement endorsement) { if (ModelState.IsValid) { db.Entry(endorsement).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(endorsement)); }
public int RefreshEndorsements() { IEnumerable <Endorsement> rg = Endorsement.EndorsementsForUser(Student, Instructor); gvExistingEndorsements.DataSource = rg; gvExistingEndorsements.DataBind(); int cItems = rg.Count(); return(cItems); }
private AirPricingSolution AddAirPriceSolution(AirService.AirPricingSolution lowestPrice, AirService.AirItinerary airItinerary) { AirPricingSolution finalPrice = new AirPricingSolution() { Key = lowestPrice.Key, TotalPrice = lowestPrice.TotalPrice, BasePrice = lowestPrice.BasePrice, ApproximateTotalPrice = lowestPrice.ApproximateTotalPrice, ApproximateBasePrice = lowestPrice.ApproximateBasePrice, Taxes = lowestPrice.Taxes, ApproximateTaxes = lowestPrice.ApproximateTaxes, QuoteDate = lowestPrice.QuoteDate }; List<typeBaseAirSegment> finalSegments = new List<typeBaseAirSegment>(); List<AirPricingInfo> finalPriceInfo =new List<AirPricingInfo>(); foreach (var segmentRef in lowestPrice.AirSegmentRef) { foreach (var segment in airItinerary.AirSegment) { if (segmentRef.Key.CompareTo(segment.Key) == 0) { typeBaseAirSegment univSeg = new typeBaseAirSegment() { ArrivalTime = segment.ArrivalTime, AvailabilityDisplayType = segment.AvailabilityDisplayType, AvailabilitySource = segment.AvailabilitySource, Carrier = segment.Carrier, ChangeOfPlane = segment.ChangeOfPlane, ClassOfService = segment.ClassOfService, DepartureTime = segment.DepartureTime, Destination = segment.Destination, Distance = segment.Distance, Equipment = segment.Equipment, FlightNumber = segment.FlightNumber, FlightTime = segment.FlightTime, Group = segment.Group, Key = segment.Key, LinkAvailability = segment.LinkAvailability, OptionalServicesIndicator = segment.OptionalServicesIndicator, Origin = segment.Origin, ParticipantLevel = segment.ParticipantLevel, PolledAvailabilityOption = segment.PolledAvailabilityOption, ProviderCode = segment.ProviderCode, TravelTime = segment.TravelTime, }; finalSegments.Add(univSeg); break; } } } foreach (var priceInfo in lowestPrice.AirPricingInfo) { AirPricingInfo info = new AirPricingInfo() { ApproximateBasePrice = priceInfo.ApproximateBasePrice, ApproximateTotalPrice = priceInfo.ApproximateTotalPrice, BasePrice = priceInfo.BasePrice, ETicketability = (typeEticketability)priceInfo.ETicketability, IncludesVAT = priceInfo.IncludesVAT, Key = priceInfo.Key, LatestTicketingTime = priceInfo.LatestTicketingTime, //PlatingCarrier = priceInfo.PlatingCarrier, Optional but might be required for some carriers PricingMethod = (typePricingMethod)priceInfo.PricingMethod, ProviderCode = priceInfo.ProviderCode, Taxes = priceInfo.Taxes, TotalPrice = priceInfo.TotalPrice, }; List<FareInfo> fareInfoList = new List<FareInfo>(); List<ManualFareAdjustment> fareAdjustmentList = new List<ManualFareAdjustment>(); ManualFareAdjustment adjustment = new ManualFareAdjustment() { AdjustmentType = typeAdjustmentType.Amount, AppliedOn = typeAdjustmentTarget.Base, Value = +40, PassengerRef = "gr8AVWGCR064r57Jt0+8bA==" }; fareAdjustmentList.Add(adjustment); info.AirPricingModifiers = new AirPricingModifiers() { ManualFareAdjustment = fareAdjustmentList.ToArray() }; foreach (var fareInfo in priceInfo.FareInfo) { FareInfo createInfo = new FareInfo() { Amount = fareInfo.Amount, DepartureDate = fareInfo.DepartureDate, Destination = fareInfo.Destination, EffectiveDate = fareInfo.EffectiveDate, FareBasis = fareInfo.FareBasis, Key = fareInfo.Key, NotValidAfter = fareInfo.NotValidAfter, NotValidBefore = fareInfo.NotValidBefore, Origin = fareInfo.Origin, PassengerTypeCode = fareInfo.PassengerTypeCode, PrivateFare = (typePrivateFare)fareInfo.PrivateFare, PseudoCityCode = fareInfo.PseudoCityCode, FareRuleKey = new FareRuleKey() { FareInfoRef = fareInfo.FareRuleKey.FareInfoRef, ProviderCode = fareInfo.FareRuleKey.ProviderCode, Value = fareInfo.FareRuleKey.Value } }; List<Endorsement> endorsementList = new List<Endorsement>(); if (fareInfo.Endorsement != null) { foreach (var endorse in fareInfo.Endorsement) { Endorsement createEndorse = new Endorsement() { Value = endorse.Value }; endorsementList.Add(createEndorse); } createInfo.Endorsement = endorsementList.ToArray(); } fareInfoList.Add(createInfo); } info.FareInfo = fareInfoList.ToArray(); List<BookingInfo> bInfo = new List<BookingInfo>(); foreach (var bookingInfo in priceInfo.BookingInfo) { BookingInfo createBookingInfo = new BookingInfo() { BookingCode = bookingInfo.BookingCode, CabinClass = bookingInfo.CabinClass, FareInfoRef = bookingInfo.FareInfoRef, SegmentRef = bookingInfo.SegmentRef }; bInfo.Add(createBookingInfo); } info.BookingInfo = bInfo.ToArray(); List<typeTaxInfo> taxes = new List<typeTaxInfo>(); foreach (var tax in priceInfo.TaxInfo) { typeTaxInfo createTaxInfo = new typeTaxInfo() { Amount = tax.Amount, Category = tax.Category, Key = tax.Key }; taxes.Add(createTaxInfo); } info.TaxInfo = taxes.ToArray(); info.FareCalc = priceInfo.FareCalc; List<PassengerType> passengers = new List<PassengerType>(); /*foreach (var pass in priceInfo.PassengerType) { PassengerType passType = new PassengerType() { BookingTravelerRef = pass.BookingTravelerRef, Code = pass.BookingTravelerRef }; passengers.Add(passType); }*/ passengers.Add(new PassengerType() { Code = "ADT", BookingTravelerRef = "gr8AVWGCR064r57Jt0+8bA==" }); info.PassengerType = passengers.ToArray(); if (priceInfo.ChangePenalty != null) { info.ChangePenalty = new typeFarePenalty() { Amount = priceInfo.ChangePenalty.Amount }; } List<BaggageAllowanceInfo> baggageInfoList = new List<BaggageAllowanceInfo>(); foreach (var allowanceInfo in priceInfo.BaggageAllowances.BaggageAllowanceInfo) { BaggageAllowanceInfo createBaggageInfo = new BaggageAllowanceInfo() { Carrier = allowanceInfo.Carrier, Destination = allowanceInfo.Destination, Origin = allowanceInfo.Origin, TravelerType = allowanceInfo.TravelerType }; List<URLInfo> urlInfoList = new List<URLInfo>(); foreach (var url in allowanceInfo.URLInfo) { URLInfo urlInfo = new URLInfo() { URL = url.URL }; urlInfoList.Add(urlInfo); } createBaggageInfo.URLInfo = urlInfoList.ToArray(); List<ConsoleApplication1.UniversalService.TextInfo> textInfoList = new List<UniversalService.TextInfo>(); foreach (var textData in allowanceInfo.TextInfo) { ConsoleApplication1.UniversalService.TextInfo textInfo = new UniversalService.TextInfo() { Text = textData.Text }; textInfoList.Add(textInfo); } createBaggageInfo.TextInfo = textInfoList.ToArray(); List<BagDetails> bagDetailsList = new List<BagDetails>(); foreach (var bagDetails in allowanceInfo.BagDetails) { BagDetails bag = new BagDetails() { ApplicableBags = bagDetails.ApplicableBags, ApproximateBasePrice = bagDetails.ApproximateBasePrice, ApproximateTotalPrice = bagDetails.ApproximateTotalPrice, BasePrice = bagDetails.BasePrice, TotalPrice = bagDetails.TotalPrice, }; List<BaggageRestriction> bagRestictionList = new List<BaggageRestriction>(); foreach (var restriction in bagDetails.BaggageRestriction) { List<ConsoleApplication1.UniversalService.TextInfo> restrictionTextList = new List<UniversalService.TextInfo>(); foreach (var bagResTextInfo in restriction.TextInfo) { ConsoleApplication1.UniversalService.TextInfo resText = new UniversalService.TextInfo() { Text = bagResTextInfo.Text }; restrictionTextList.Add(resText); } BaggageRestriction bagRes = new BaggageRestriction() { TextInfo = restrictionTextList.ToArray() }; bagRestictionList.Add(bagRes); } bag.BaggageRestriction = bagRestictionList.ToArray(); bagDetailsList.Add(bag); } createBaggageInfo.BagDetails = bagDetailsList.ToArray(); baggageInfoList.Add(createBaggageInfo); } List<CarryOnAllowanceInfo> carryOnAllowanceList = new List<CarryOnAllowanceInfo>(); foreach (var carryOnBag in priceInfo.BaggageAllowances.CarryOnAllowanceInfo) { CarryOnAllowanceInfo carryOn = new CarryOnAllowanceInfo() { Carrier = carryOnBag.Carrier, Destination = carryOnBag.Destination, Origin = carryOnBag.Origin }; carryOnAllowanceList.Add(carryOn); } List<BaseBaggageAllowanceInfo> embargoInfoList = new List<BaseBaggageAllowanceInfo>(); if(priceInfo.BaggageAllowances.EmbargoInfo != null) { foreach(AirService.BaseBaggageAllowanceInfo embargoInfo in priceInfo.BaggageAllowances.EmbargoInfo) { BaseBaggageAllowanceInfo embargo = new BaseBaggageAllowanceInfo() { Carrier = embargoInfo.Carrier, Destination = embargoInfo.Destination, Origin = embargoInfo.Origin }; List<URLInfo> embargoURLList = new List<URLInfo>(); foreach(var embargoUrl in embargoInfo.URLInfo){ URLInfo url = new URLInfo() { URL = embargoUrl.URL, Text = embargoUrl.Text }; embargoURLList.Add(url); } embargo.URLInfo = embargoURLList.ToArray(); List<ConsoleApplication1.UniversalService.TextInfo> embargoTextList = new List<UniversalService.TextInfo>(); foreach(var embargoText in embargoInfo.TextInfo){ ConsoleApplication1.UniversalService.TextInfo text = new UniversalService.TextInfo() { Text = embargoText.Text }; embargoTextList.Add(text); } embargo.TextInfo = embargoTextList.ToArray(); embargoInfoList.Add(embargo); } } info.BaggageAllowances = new BaggageAllowances() { BaggageAllowanceInfo = baggageInfoList.ToArray(), CarryOnAllowanceInfo = carryOnAllowanceList.ToArray(), EmbargoInfo = embargoInfoList.ToArray() }; finalPriceInfo.Add(info); break; } finalPrice.AirPricingInfo = finalPriceInfo.ToArray(); finalPrice.AirSegment = finalSegments.ToArray(); return finalPrice; }