public AssociationUserAddress SaveAddress(AssociationUserAddress address) { try { using (var db = new LomsContext()) { if (address.SuburbId != null) { address.Country = null; address.State = null; } else if (address.StateId != null) address.Country = null; db.AssociationUserAddresses.ApplyChanges(address); db.SaveChanges(); return db.AssociationUserAddresses.IncludeAll("Country", "State", "State.Country", "Suburb", "Suburb.Country", "Suburb.State", "Suburb.State.Country") .FirstOrDefault(a => a.Id == address.Id); } } catch (Exception ex) { address.AddError("Error", ex.Message); return address; } }
public EntityResponse<Booking> Change(int bookingId) { try { using (var db = new LomsContext()) { db.Connection.Open(); using (var transaction = db.Connection.BeginTransaction()) { //delete all previus changing attempts db.Bookings.Where(b => b.OriginalId == bookingId).ForEach(b => db.Bookings.DeleteObject(b)); var originalBooking = db.Bookings.SingleOrDefault(b => b.Id == bookingId); //copy pick-up and drop-off endpoints var pickUpEndpoint = db.BookingEndpoints.SingleOrDefault(be => be.Id == originalBooking.PickUpEndpointId).Clone(); var dropOffEndpoint = db.BookingEndpoints.SingleOrDefault(be => be.Id == originalBooking.DropOffEndpointId).Clone(); pickUpEndpoint.ChangeTracker.ChangeTrackingEnabled = true; dropOffEndpoint.ChangeTracker.ChangeTrackingEnabled = true; pickUpEndpoint.ChangeTracker.State = ObjectState.Added; dropOffEndpoint.ChangeTracker.State = ObjectState.Added; pickUpEndpoint.Id = 0; dropOffEndpoint.Id = 0; db.BookingEndpoints.ApplyChanges(pickUpEndpoint); db.BookingEndpoints.ApplyChanges(dropOffEndpoint); db.SaveChanges(); //copy booking var booking = originalBooking.Clone(); booking.ChangeTracker.ChangeTrackingEnabled = true; booking.ChangeTracker.State = ObjectState.Added; booking.Id = 0; if (originalBooking.RefId == 0) booking.RefId = originalBooking.Id; else booking.RefId = originalBooking.RefId; booking.OriginalId = originalBooking.Id; booking.Generation = originalBooking.Generation + 1; booking.PickUpEndpointId = pickUpEndpoint.Id; booking.DropOffEndpointId = dropOffEndpoint.Id; booking.OriginalFareTypeId = originalBooking.FareTypeId; db.Bookings.ApplyChanges(booking); //update initial booking originalBooking.Changing = true; db.Bookings.ApplyChanges(originalBooking); db.SaveChanges(); //copy fare info var fareInfo = db.BookingFareInfoes.SingleOrDefault(i => i.BookingId == bookingId).Clone(); fareInfo.ChangeTracker.ChangeTrackingEnabled = true; fareInfo.ChangeTracker.State = ObjectState.Added; fareInfo.BookingId = booking.Id; db.BookingFareInfoes.ApplyChanges(fareInfo); db.SaveChanges(); //copy fareInfo info items var fareInfoItems = db.BookingFareInfoItems.Where(i => i.BookingId == bookingId); fareInfoItems.ForEach(i => { var tmp = i.Clone(); tmp.ChangeTracker.ChangeTrackingEnabled = true; tmp.ChangeTracker.State = ObjectState.Added; tmp.Id = 0; tmp.BookingId = booking.Id; db.BookingFareInfoItems.ApplyChanges(tmp); }); db.SaveChanges(); //copy passenger info var passengerInfo = db.BookingPassengerInfoes.SingleOrDefault(i => i.BookingId == bookingId).Clone(); passengerInfo.ChangeTracker.ChangeTrackingEnabled = true; passengerInfo.ChangeTracker.State = ObjectState.Added; passengerInfo.BookingId = booking.Id; db.BookingPassengerInfoes.ApplyChanges(passengerInfo); db.SaveChanges(); //copy passenger info items var passengerInfoAdults = db.BookingPassengerInfoAdults.Where(i => i.BookingId == bookingId); passengerInfoAdults.ForEach(i => { var tmp = i.Clone(); tmp.ChangeTracker.ChangeTrackingEnabled = true; tmp.ChangeTracker.State = ObjectState.Added; tmp.Id = 0; tmp.BookingId = booking.Id; db.BookingPassengerInfoAdults.ApplyChanges(tmp); }); var passengerInfoChilds = db.BookingPassengerInfoChilds.Where(i => i.BookingId == bookingId); passengerInfoChilds.ForEach(i => { var tmp = i.Clone(); tmp.ChangeTracker.ChangeTrackingEnabled = true; tmp.ChangeTracker.State = ObjectState.Added; tmp.Id = 0; tmp.BookingId = booking.Id; db.BookingPassengerInfoChilds.ApplyChanges(tmp); }); var passengerInfoInfants = db.BookingPassengerInfoInfants.Where(i => i.BookingId == bookingId); passengerInfoInfants.ForEach(i => { var tmp = i.Clone(); tmp.ChangeTracker.ChangeTrackingEnabled = true; tmp.ChangeTracker.State = ObjectState.Added; tmp.Id = 0; tmp.BookingId = booking.Id; db.BookingPassengerInfoInfants.ApplyChanges(tmp); }); db.SaveChanges(); //copy provision info var provisionInfo = db.BookingProvisionInfoes.SingleOrDefault(i => i.BookingId == bookingId).Clone(); provisionInfo.ChangeTracker.ChangeTrackingEnabled = true; provisionInfo.ChangeTracker.State = ObjectState.Added; provisionInfo.BookingId = booking.Id; db.BookingProvisionInfoes.ApplyChanges(provisionInfo); db.SaveChanges(); //copy charge info var chargeInfo = db.BookingChargeInfoes.SingleOrDefault(i => i.BookingId == bookingId).Clone(); chargeInfo = chargeInfo.Clone(); chargeInfo.ChangeTracker.ChangeTrackingEnabled = true; chargeInfo.ChangeTracker.State = ObjectState.Added; chargeInfo.BookingId = booking.Id; db.BookingChargeInfoes.ApplyChanges(chargeInfo); db.SaveChanges(); //copy charge info items var chargeItems = db.BookingChargeInfoItems.Where(i => i.BookingId == bookingId); chargeItems.ForEach(i => { var tmp = i.Clone(); tmp.ChangeTracker.ChangeTrackingEnabled = true; tmp.ChangeTracker.State = ObjectState.Added; tmp.Id = 0; tmp.BookingId = booking.Id; db.BookingChargeInfoItems.ApplyChanges(tmp); }); //copy transaction credit card var transactionCreditCards = db.BookingTransactionCreditCards.Where(i => i.BookingId == bookingId); transactionCreditCards.ForEach(cc => { var creditCard = cc.Clone(); creditCard.ChangeTracker.ChangeTrackingEnabled = true; creditCard.ChangeTracker.State = ObjectState.Added; creditCard.Id = 0; creditCard.BookingId = booking.Id; db.BookingTransactionCreditCards.ApplyChanges(creditCard); db.SaveChanges(); var paymentInfoCreditCardAddress = db.BookingTransactionCreditCardAddresses.SingleOrDefault(a => a.CreditCardId == cc.Id).Clone(); if (paymentInfoCreditCardAddress != null) { paymentInfoCreditCardAddress.ChangeTracker.ChangeTrackingEnabled = true; paymentInfoCreditCardAddress.ChangeTracker.State = ObjectState.Added; paymentInfoCreditCardAddress.CreditCardId = creditCard.Id; db.BookingTransactionCreditCardAddresses.ApplyChanges(paymentInfoCreditCardAddress); } var paymentInfoCreditCardInfo = db.BookingTransactionCreditCardInfoes.SingleOrDefault(i => i.CreditCardId == cc.Id).Clone(); if (paymentInfoCreditCardInfo != null) { paymentInfoCreditCardInfo.ChangeTracker.ChangeTrackingEnabled = true; paymentInfoCreditCardInfo.ChangeTracker.State = ObjectState.Added; paymentInfoCreditCardInfo.CreditCardId = creditCard.Id; db.BookingTransactionCreditCardInfoes.ApplyChanges(paymentInfoCreditCardInfo); } db.SaveChanges(); }); //if (paymentInfoCreditCard != null) //{ // paymentInfoCreditCard.ChangeTracker.ChangeTrackingEnabled = true; // paymentInfoCreditCard.ChangeTracker.State = ObjectState.Added; // paymentInfoCreditCard.CreditCardId = booking.Id; // db.BookingPaymentCreditCards.ApplyChanges(paymentInfoCreditCard); // db.SaveChanges(); // var paymentInfoCreditCardAddress = db.BookingPaymentCreditCardAddresses.SingleOrDefault(i => i.CreditCardId == bookingId).Clone(); // if (paymentInfoCreditCardAddress != null) // { // paymentInfoCreditCardAddress.ChangeTracker.ChangeTrackingEnabled = true; // paymentInfoCreditCardAddress.ChangeTracker.State = ObjectState.Added; // paymentInfoCreditCardAddress.CreditCardId = booking.Id; // db.BookingPaymentCreditCardAddresses.ApplyChanges(paymentInfoCreditCardAddress); // } // var paymentInfoCreditCardInfo = db.BookingPaymentCreditCardInfoes.SingleOrDefault(i => i.CardId == bookingId).Clone(); // if (paymentInfoCreditCardInfo != null) // { // paymentInfoCreditCardInfo.ChangeTracker.ChangeTrackingEnabled = true; // paymentInfoCreditCardInfo.ChangeTracker.State = ObjectState.Added; // paymentInfoCreditCardInfo.CardId = booking.Id; // db.BookingPaymentCreditCardInfoes.ApplyChanges(paymentInfoCreditCardInfo); // } // db.SaveChanges(); //} //copy payment info //var paymentInfo = db.BookingPayments.SingleOrDefault(i => i.BookingId == bookingId).Clone(); //paymentInfo.ChangeTracker.ChangeTrackingEnabled = true; //paymentInfo.ChangeTracker.State = ObjectState.Added; //paymentInfo.BookingId = booking.Id; //db.BookingPayments.ApplyChanges(paymentInfo); //db.SaveChanges(); //copy payment info items //var paymentInfoItems = db.BookingPaymentItems.Where(i => i.BookingId == bookingId); //paymentInfoItems.ForEach(i => //{ // var tmp = i.Clone(); // tmp.ChangeTracker.ChangeTrackingEnabled = true; // tmp.ChangeTracker.State = ObjectState.Added; // tmp.Id = 0; // tmp.BookingId = booking.Id; // db.BookingPaymentItems.ApplyChanges(tmp); //}); //db.SaveChanges(); //copy payment billing account //var paymentInfoBillingAccount = db.BookingPaymentBillingAccounts.SingleOrDefault(i => i.BillingAccountId == bookingId).Clone(); //if (paymentInfoBillingAccount != null) //{ // paymentInfoBillingAccount.ChangeTracker.ChangeTrackingEnabled = true; // paymentInfoBillingAccount.ChangeTracker.State = ObjectState.Added; // paymentInfoBillingAccount.BillingAccountId = booking.Id; // db.BookingPaymentBillingAccounts.ApplyChanges(paymentInfoBillingAccount); // db.SaveChanges(); //} //copy payment credit card //var paymentInfoCreditCard = db.BookingPaymentCreditCards.SingleOrDefault(i => i.CreditCardId == bookingId).Clone(); //if (paymentInfoCreditCard != null) //{ // paymentInfoCreditCard.ChangeTracker.ChangeTrackingEnabled = true; // paymentInfoCreditCard.ChangeTracker.State = ObjectState.Added; // paymentInfoCreditCard.CreditCardId = booking.Id; // db.BookingPaymentCreditCards.ApplyChanges(paymentInfoCreditCard); // db.SaveChanges(); // var paymentInfoCreditCardAddress = db.BookingPaymentCreditCardAddresses.SingleOrDefault(i => i.CreditCardId == bookingId).Clone(); // if (paymentInfoCreditCardAddress != null) // { // paymentInfoCreditCardAddress.ChangeTracker.ChangeTrackingEnabled = true; // paymentInfoCreditCardAddress.ChangeTracker.State = ObjectState.Added; // paymentInfoCreditCardAddress.CreditCardId = booking.Id; // db.BookingPaymentCreditCardAddresses.ApplyChanges(paymentInfoCreditCardAddress); // } // var paymentInfoCreditCardInfo = db.BookingPaymentCreditCardInfoes.SingleOrDefault(i => i.CardId == bookingId).Clone(); // if (paymentInfoCreditCardInfo != null) // { // paymentInfoCreditCardInfo.ChangeTracker.ChangeTrackingEnabled = true; // paymentInfoCreditCardInfo.ChangeTracker.State = ObjectState.Added; // paymentInfoCreditCardInfo.CardId = booking.Id; // db.BookingPaymentCreditCardInfoes.ApplyChanges(paymentInfoCreditCardInfo); // } // db.SaveChanges(); //} ////copy payment info to history //var paymentHistory = new BookingPaymentHistory() { BookingId = booking.Id }; //paymentHistory.Amount = paymentInfo.Amount; //paymentHistory.AssociationUserId = paymentHistory.AssociationUserId; //db.BookingPaymentHistories.ApplyChanges(paymentHistory); //db.SaveChanges(); //if (paymentInfoBillingAccount != null) //{ // var paymentHistoryBillingAccount = new BookingPaymentHistoryBillingAccount() // { // BillingAccountId = paymentHistory.Id, // ChargeBackId = paymentInfoBillingAccount.ChargeBackId, // BillingCode = paymentInfoBillingAccount.BillingCode, // Email = paymentInfoBillingAccount.Email, // ContactPerson = paymentInfoBillingAccount.ContactPerson, // ContactNumber = paymentInfoBillingAccount.ContactNumber, // SavedBillingAccountId = paymentInfoBillingAccount.SavedBillingAccountId, // SavedBillingAccountNickname = paymentInfoBillingAccount.SavedBillingAccountNickname, // SavedBillingAccountIsDefaultBilling = paymentInfoBillingAccount.SavedBillingAccountIsDefaultBilling // }; // db.BookingPaymentHistoryBillingAccounts.ApplyChanges(paymentHistoryBillingAccount); // db.SaveChanges(); //} //if (paymentInfoCreditCard != null) //{ // var paymentHistoryCreditCard = new BookingPaymentHistoryCreditCard() // { // CreditCardId = paymentHistory.Id, // TypeId = paymentInfoCreditCard.TypeId, // Holder = paymentInfoCreditCard.Holder, // ExpiryMonth = paymentInfoCreditCard.ExpiryMonth, // ExpiryYear = paymentInfoCreditCard.ExpiryYear, // SavedCreditCardId = paymentInfoCreditCard.SavedCreditCardId, // SavedCreditCardNickname = paymentInfoCreditCard.SavedCreditCardNickname, // SavedCrediCardIsDefaultBilling = paymentInfoCreditCard.SavedCrediCardIsDefaultBilling, // PaymentApi = paymentInfoCreditCard.PaymentApi, // OrderNumber = paymentInfoCreditCard.OrderNumber, // }; // db.BookingPaymentHistoryCreditCards.ApplyChanges(paymentHistoryCreditCard); // db.SaveChanges(); // var paymentInfoCreditCardAddress = db.BookingPaymentCreditCardAddresses.SingleOrDefault(i => i.CreditCardId == bookingId); // if (paymentInfoCreditCardAddress != null) // { // var paymentHistoryCreditCardAddress = new BookingPaymentHistoryCreditCardAddress() // { // CreditCardId = paymentHistoryCreditCard.CreditCardId, // CountryId = paymentInfoCreditCardAddress.CountryId, // StateId = paymentInfoCreditCardAddress.StateId, // BuildingName = paymentInfoCreditCardAddress.BuildingName, // Address1 = paymentInfoCreditCardAddress.Address1, // Address2 = paymentInfoCreditCardAddress.Address2, // SuburbName = paymentInfoCreditCardAddress.SuburbName, // SuburbCode = paymentInfoCreditCardAddress.SuburbCode, // }; // db.BookingPaymentHistoryCreditCardAddresses.ApplyChanges(paymentHistoryCreditCardAddress); // db.SaveChanges(); // } // db.SaveChanges(); // var paymentInfoCreditCardInfo = db.BookingPaymentCreditCardInfoes.SingleOrDefault(i => i.CardId == bookingId); // if (paymentInfoCreditCardInfo != null) // { // var paymentHistoryCreditCardInfo = new BookingPaymentHistoryCreditCardInfo() // { // CardId = paymentHistoryCreditCard.CreditCardId, // Number = paymentInfoCreditCardInfo.Number, // CVC = paymentInfoCreditCardInfo.CVC // }; // db.BookingPaymentHistoryCreditCardInfoes.ApplyChanges(paymentHistoryCreditCardInfo); // db.SaveChanges(); // } // db.SaveChanges(); //} bookingId = booking.Id; transaction.Commit(); } } return new EntityResponse<Booking>(GetBooking2(bookingId)); } catch (Exception ex) { StringBuilder builder = new StringBuilder(); builder.AppendLine(ex.Message); if (ex.InnerException != null) { builder.AppendLine(ex.InnerException.Message); if (ex.InnerException.InnerException != null) builder.AppendLine(ex.InnerException.InnerException.Message); } return new EntityResponse<Booking>(builder.ToString()); } }
protected void btnActivate_Click(object sender, EventArgs e) { string guidStr = Page.RouteData.Values["guid"] as string; Guid guid; if (guidStr == null || !Guid.TryParseExact(guidStr, "D", out guid)) { multiView1.SetActiveView(viewError); lblError.Text = "Wrong reset guid!"; return; } else { using (var db = new LomsContext()) { var pwdReset = db.AssociationUserPasswordResets.FirstOrDefault(a => a.Guid == guid); if (pwdReset == null) { multiView1.SetActiveView(viewError); lblError.Text = "Wrong reset guid!"; return; } //validate password string pwd = txtPassword.Text.Trim(); string pwd2 = txtConfirmPassword.Text.Trim(); bool notValidated = false; if (string.IsNullOrEmpty(pwd)) { notValidated |= lblPasswordNote.Visible = true; lblComfirmPasswordNote.Text = "Password is required."; } if (string.IsNullOrEmpty(pwd2)) { notValidated |= lblComfirmPasswordNote.Visible = true; lblComfirmPasswordNote.Text = "Confirm Password is required."; } else if (pwd != pwd2) { notValidated |= lblComfirmPasswordNote.Visible = true; lblComfirmPasswordNote.Text = "Confirm Password does not match to Password."; } if (notValidated) return; var user = db.AssociationUsers.First(u => u.Id == pwdReset.AssociationUserId); var membershipUser = Membership.GetUser(user.Email); if (membershipUser == null) { multiView1.SetActiveView(viewError); lblError.Text = "Wrong email!"; return; } string tempPwd = membershipUser.ResetPassword(); membershipUser.ChangePassword(tempPwd, pwd); db.AssociationUserPasswordResets.DeleteObject(pwdReset); db.SaveChanges(); multiView1.SetActiveView(viewSuccess); lblInfo2.Visible = lblInfo21.Visible = lblInfo3.Visible = lblInfo4.Visible = true; //lblInfo.Text = string.Format("Congratulations {0} {1}!", user.FirstName.ToUpper(), user.LastName.ToUpper()); lblInfo.Text = string.Format("Congratulations!"); lblInfo2.Text = string.Format("Your password has been changed"); lblInfo21.Text = ""; //lblInfo21.Text = string.Format("Your password has been sent to {0}.", user.Email); lblInfo3.Text = "We look forward to providing you with our on-time guaranteed services for all your journeys."; lblInfo4.Text = "Once again if you require any further assistance feel free to contact us."; } } }
public void SetNoAvailability(int bookingId) { using (var db = new LomsContext()) { db.Connection.Open(); using (var transaction = db.Connection.BeginTransaction()) { var bookingQuote = db.BookingQuotations.Single(q => q.BookingId == bookingId); bookingQuote.Status = QuotationStatus.NoAvailability; db.BookingQuotations.ApplyChanges(bookingQuote); var booking = db.Bookings.IncludeAll("FareInfo", "FareInfo.Currency", "FareInfo.Items", "AllocatedVehicle").Single(b => b.Id == bookingId); booking.Status = BookingStatus.QuoteUnavailable; booking.ClearFareInfo(); booking.ClearAllocatedVehicle(); db.Bookings.ApplyChanges(booking); db.SaveChanges(); transaction.Commit(); } } }
public EntityResponse<AssociationUser> ActivateSupervisor(Guid guid) { try { using (var db = new LomsContext()) { db.Connection.Open(); using (var transaction = db.Connection.BeginTransaction()) { var activation = db.AssociationUserTravelAgencyRoleActivations.FirstOrDefault(a => a.Guid == guid); if (activation == null) return new EntityResponse<AssociationUser>("Wrong activation guid!"); var role = db.AssociationUserTravelAgencyRoles.First(m => m.UserId == activation.UserId); if (DateTime.UtcNow > activation.ExpiryTime) { role.Status = TravelAgencyStatus.Expired; db.AssociationUserTravelAgencyRoles.ApplyChanges(role); db.AssociationUserTravelAgencyRoleActivations.DeleteObject(activation); db.SaveChanges(); return new EntityResponse<AssociationUser>("Time period for activation is over. Ask group manager to send new invitation."); } role.Status = TravelAgencyStatus.Accepted; db.AssociationUserTravelAgencyRoles.ApplyChanges(role); db.AssociationUserTravelAgencyRoleActivations.DeleteObject(activation); db.SaveChanges(); var user = db.AssociationUsers.Single(u => u.Id == role.UserId); db.SaveChanges(); transaction.Commit(); return new EntityResponse<AssociationUser>() { Entity = user }; } } } catch (Exception ex) { StringBuilder builder = new StringBuilder(); builder.AppendLine(ex.Message); if (ex.InnerException != null) { builder.AppendLine(ex.InnerException.Message); if (ex.InnerException.InnerException != null) builder.AppendLine(ex.InnerException.InnerException.Message); } return new EntityResponse<AssociationUser>(builder.ToString()); } }
public string ResetClientPassword(string email) { try { if (string.IsNullOrWhiteSpace(email)) return "Email cannot be empty!"; email = email.Trim().ToLower(); using (var db = new LomsContext()) { //check id user with such email existed already var existedUser = (from u in db.AssociationUsers where u.AssociationId == CurrentAssociationId && u.Email == email select u).SingleOrDefault(); if (existedUser == null) return "Not a registered user!"; if (!existedUser.HasOnlineAccess) return "Not a with online access!"; var pwdReset = db.AssociationUserPasswordResets.SingleOrDefault(r => r.AssociationUserId == existedUser.Id); if (pwdReset == null) { pwdReset = new AssociationUserPasswordReset(); pwdReset.AssociationUserId = existedUser.Id; } pwdReset.Guid = Guid.NewGuid(); pwdReset.Time = DateTime.UtcNow.AddHours(2.0); db.AssociationUserPasswordResets.ApplyChanges(pwdReset); db.SaveChanges(); var emailProvider = db.AssociationEmails.FirstOrDefault(e => e.AssociationId == CurrentAssociationId); if (emailProvider != null) { var association = db.Associations.FirstOrDefault(a => a.Id == CurrentAssociationId); var uri = HttpContext.Current.Request.Url; string baseUrl = String.Format("{0}://{1}:{2}", uri.Scheme, uri.Host ?? "80", uri.Port); string activtionLink = Path.Combine(baseUrl + string.Format("/#PasswordReset/{0}", pwdReset.Guid.ToString("D"))); string contactUsLink = Path.Combine(baseUrl + "/#Contact"); var emailTemplate = new EmailTemplate("PasswordReset"); emailTemplate["UserName"] = existedUser.FullName.ToUpper(); emailTemplate["ActivationLink"] = activtionLink; emailTemplate["ContactUsLink"] = contactUsLink; var avBody = AlternateView.CreateAlternateViewFromString(emailTemplate.Html, null, MediaTypeNames.Text.Html); emailProvider.SendMail(existedUser.Email, association.Name + " - Reset you Password", emailTemplate.Txt, null, avBody, true); } return ""; } } catch (Exception ex) { StringBuilder builder = new StringBuilder(); builder.AppendLine(ex.Message); if (ex.InnerException != null) { builder.AppendLine(ex.InnerException.Message); if (ex.InnerException.InnerException != null) builder.AppendLine(ex.InnerException.InnerException.Message); } return builder.ToString(); } }
public ActivateClientResponse ActivateClient(Guid guid) { try { using (var db = new LomsContext()) { db.Connection.Open(); using (var transaction = db.Connection.BeginTransaction()) { var activation = db.AssociationUserActivations.FirstOrDefault(a => a.Guid == guid); if (activation == null) return new ActivateClientResponse("Wrong activation guid!"); db.AssociationUserActivations.DeleteObject(activation); db.SaveChanges(); var user = db.AssociationUsers.Single(u => u.Id == activation.UserId); if (user.AspNetUserId != null) { //update membership var userMembership = Membership.GetUser(user.AspNetUserId); userMembership.IsApproved = true; Membership.UpdateUser(userMembership); transaction.Commit(); return new ActivateClientResponse() { Entity = user }; } else return new ActivateClientResponse() { Entity = user, IsPasswordRequired = true }; } } } catch (Exception ex) { StringBuilder builder = new StringBuilder(); builder.AppendLine(ex.Message); if (ex.InnerException != null) { builder.AppendLine(ex.InnerException.Message); if (ex.InnerException.InnerException != null) builder.AppendLine(ex.InnerException.InnerException.Message); } return new ActivateClientResponse(builder.ToString()); } }
public void SetSupplierPriorities(int cityId, int vehicleTypeId, IEnumerable<DispatchSupplier> orderedSuppliers) { using (var db = new LomsContext()) { int priority = 0; foreach (var supplier in orderedSuppliers) { var query = from sc in db.DispatchSupplierCities join scvt in db.DispatchSupplierCityVehicleTypes on sc.Id equals scvt.SupplierCityId where sc.SupplierId == supplier.Id && sc.CityId == cityId && scvt.VehicleTypeId == vehicleTypeId select scvt; var supplierCityVehicleType = query.SingleOrDefault(); if (supplierCityVehicleType == null) continue; supplierCityVehicleType.Priority = priority++; db.DispatchSupplierCityVehicleTypes.ApplyChanges(supplierCityVehicleType); } db.SaveChanges(); } }
public BookingStatus SaveBookingPendingContectMethod(int bookingId, PendingContactMethod method) { using (var db = new LomsContext()) { db.Connection.Open(); using (var transaction = db.Connection.BeginTransaction()) { var booking = db.Bookings.FirstOrDefault(b => b.Id == bookingId); var time = booking.ExpiryTime - DateTime.UtcNow; if (time <= TimeSpan.Zero) return BookingStatus.Expired; booking.Status = BookingStatus.PendingSubmitted; booking.PendingContactMethod = method; db.Bookings.ApplyChanges(booking); var bookingQuotation = new BookingQuotation() { BookingId = bookingId, Status = QuotationStatus.Pending }; bookingQuotation.Time = GetCityLocalTime(booking.CityId); db.BookingQuotations.ApplyChanges(bookingQuotation); db.SaveChanges(); transaction.Commit(); } return BookingStatus.PendingSubmitted; } }
public BookingResponse GetBookingWithFareInfo(int bookingId) { DebugWriter debugInfoWriter = new DebugWriter(); try { DateTime utc = DateTime.UtcNow; using (var db = new LomsContext()) { var booking = GetBooking(db, bookingId); if (!booking.CreatorId.HasValue) { booking.CreatorId = CurrentUserId(); booking.PrimaryPassengerId = CurrentUserId(); } //generate fares if (booking.Status == BookingStatus.InProgress) { if (booking.FareInfo == null) booking.FareInfo = new BookingFareInfo() { BookingId = booking.Id }; //vehicle availability if (VehicleAvailabilityHelper.AllocateVehicle(db, booking, true, debugInfoWriter.GetStringBuilder())) //phantom { booking.Status = BookingStatus.Fare; FillBookingWithFareInfo(db, booking, debugInfoWriter); if (booking.FareInfo.Price == 0) booking.Status = BookingStatus.Pending; utc = DateTime.UtcNow; booking.ExpiryTime = utc.AddMinutes(10.0); } else if (VehicleAvailabilityHelper.AllocateVehicle(db, booking, false, debugInfoWriter.GetStringBuilder())) //pending { booking.Status = BookingStatus.Pending; FillBookingWithFareInfo(db, booking, debugInfoWriter); utc = DateTime.UtcNow; booking.ExpiryTime = utc.AddMinutes(10.0); } else { booking.Status = BookingStatus.NoAvailability; booking.ExpiryTime = null; } } db.Bookings.ApplyChanges(booking); db.SaveChanges(); booking = GetBooking(db, booking.Id); return new BookingResponse { Booking = booking, DebugInfo = debugInfoWriter.ToString(), ServerUtcTime = utc }; } } catch (Exception ex) { var response = new BookingResponse() { DebugInfo = debugInfoWriter.ToString() }; response.AddError("Response", ex.ToString()); return response; } }
public BookingResponse SaveBookingPickUpTimeDropOffTimeAndPromoCode(int bookingId, DateTime pickUptime, DateTime? dropOffTime, string promoCode) { DebugWriter debugInfoWriter = new DebugWriter(); try { using (var db = new LomsContext()) { var booking = db.Bookings.IncludeAll("FareInfo", "FareInfo.Items").FirstOrDefault(b => b.Id == bookingId); if (booking.PickUpTime != pickUptime) { booking.PickUpTime = pickUptime; booking.OnPickUpTimeChanged(); } if (booking.DropOffTime != dropOffTime) { booking.DropOffTime = dropOffTime; booking.OnDropOffTimeChanged(); } if (booking.PromoCode != promoCode) { booking.PromoCode = promoCode; booking.OnPromoCodeChanged(); } db.Bookings.ApplyChanges(booking); db.SaveChanges(); booking = GetBooking(db, booking.Id); return new BookingResponse { Booking = booking, DebugInfo = debugInfoWriter.ToString() }; } } catch (Exception ex) { var response = new BookingResponse() { DebugInfo = debugInfoWriter.ToString() }; response.AddError("Response", ex.ToString()); return response; } }
public BookingResponse SaveBookingVehicleType(int bookingId, int vehicleTypeId) { try { using (var db = new LomsContext()) { var booking = GetBooking(db, bookingId); if (booking.VehicleTypeId != vehicleTypeId) { booking.VehicleTypeId = vehicleTypeId; booking.OnVehicleTypeChanged(); db.Bookings.ApplyChanges(booking); db.SaveChanges(); } booking = GetBooking(db, booking.Id); return new BookingResponse { Booking = booking }; } } catch (Exception ex) { var response = new BookingResponse(); response.AddError("Response", ex.ToString()); return response; } }
public BookingResponse SaveBookingStops(int bookingId, IEnumerable<BookingStop> stops) { try { using (var db = new LomsContext()) { var booking = GetBooking(db, bookingId); //remove foreach (var stop in booking.Stops) if (!stops.Any(s => s.Id == stop.Id)) stop.MarkAsDeleted(); //add stops.Where(s => s.Id == 0) .ForEach(s => { s.ClearPropertiesButSkipKeys(); var newStop = new BookingStop(); newStop.SetDataFrom(s); booking.Stops.Add(newStop); }); //update stops.Where(s => s.Id != 0).ForEach(s => booking.Stops.First(bs => bs.Id == s.Id).SetDataFrom(s)); db.Bookings.ApplyChanges(booking); db.SaveChanges(); booking = GetBooking(db, booking.Id); return new BookingResponse { Booking = booking }; } } catch (Exception ex) { var response = new BookingResponse(); response.AddError("Response", ex.ToString()); return response; } }
public BookingResponse SaveBookingDropOffEndpoint(int bookingId, BookingEndpoint endpoint) { try { using (var db = new LomsContext()) { var booking = GetBooking(db, bookingId); if (booking.DropOffEndpoint.Type != endpoint.Type || booking.DropOffEndpoint.Address1 != endpoint.Address1 || booking.DropOffEndpoint.SuburbId != endpoint.SuburbId || booking.DropOffEndpoint.AirportId != endpoint.AirportId) { booking.OnDropOffEndpointChanged(); } booking.DropOffEndpoint.SetDataFrom(endpoint); //airport default city if (booking.JourneyType == JourneyType.ToAirport) if (booking.DropOffEndpoint.Type == BookingEndpointType.AirportOther || booking.DropOffEndpoint.Type == BookingEndpointType.AirportPrivate) { var airportDefaultCity = db.AirportCities.SingleOrDefault(a => a.AirportId == booking.DropOffEndpoint.AirportId && a.IsDefault); if (airportDefaultCity != null && booking.CityId != airportDefaultCity.CityId) booking.CityId = airportDefaultCity.CityId; } db.Bookings.ApplyChanges(booking); db.SaveChanges(); booking = GetBooking(db, bookingId); return new BookingResponse { Booking = booking }; } } catch (Exception ex) { var response = new BookingResponse(); response.AddError("Response", ex.ToString()); return response; } }
public BookingResponse SaveBookingJourneyType(int bookingId, JourneyType journeyType) { try { using (var db = new LomsContext()) { var booking = GetBooking(db, bookingId); if (booking.JourneyType != journeyType) { booking.JourneyType = journeyType; booking.OnJourneyTypeChanged(); db.Bookings.ApplyChanges(booking); db.SaveChanges(); } booking = GetBooking(db, booking.Id); return new BookingResponse { Booking = booking }; } } catch (Exception ex) { var response = new BookingResponse(); response.AddError("Response", ex.ToString()); return response; } }
public void DeleteWorldwideUser(int userId) { using (var db = new LomsContext()) { var user = new DispatchUser() { Id = userId }; db.DispatchUsers.Attach(user); db.DispatchUsers.DeleteObject(user); db.SaveChanges(); } }
public EntityResponse<DispatchSupplier> AddSupplier(AddSupplierRequest request) { try { var supplier = request.Supplier; using (var scope = new TransactionScope()) { using (var db = new LomsContext()) { if (supplier.Suburb != null) { supplier.Country = null; supplier.State = null; } else if (supplier.State != null) supplier.Country = null; db.DispatchSuppliers.ApplyChanges(supplier); db.SaveChanges(); //create manager var user = request.Manager; user.SupplierId = supplier.Id; user.Login = "******"; db.DispatchSupplierUsers.ApplyChanges(user); db.SaveChanges(); user.Login = string.Format("sup{0:000}-{1:000}", supplier.Id, user.Id); user.Role = SupplierUserRole.Manager; if (request.HasOnlineAccess) { MembershipCreateStatus ret; MembershipUser membershipUser = Membership.CreateUser(user.Login, request.ManagerPassword, user.Email, "Who am I?", "I", true, null, out ret); if (ret != MembershipCreateStatus.Success) throw new ApplicationException(ret.ToString()); user.AspNetUserId = (Guid)membershipUser.ProviderUserKey; if (!Roles.RoleExists(RoleName.SupplierUser)) Roles.CreateRole(RoleName.SupplierUser); if (!Roles.RoleExists(RoleName.SupplierManager)) Roles.CreateRole(RoleName.SupplierManager); if (!Roles.IsUserInRole(user.Login, RoleName.SupplierUser)) Roles.AddUserToRole(user.Login, RoleName.SupplierUser); if (user.Role == SupplierUserRole.Manager && !Roles.IsUserInRole(user.Login, RoleName.SupplierManager)) Roles.AddUserToRole(user.Login, RoleName.SupplierManager); else if (user.Role != SupplierUserRole.Manager && Roles.IsUserInRole(user.Login, RoleName.SupplierManager)) Roles.RemoveUserFromRole(user.Login, RoleName.SupplierManager); } db.DispatchSupplierUsers.ApplyChanges(user); db.SaveChanges(); } //save cities foreach (var supplierCity in request.Cities) { using (var db = new LomsContext()) { supplierCity.SupplierId = supplier.Id; db.DispatchSupplierCities.ApplyChanges(supplierCity); db.SaveChanges(); } } scope.Complete(); } using (var db = new LomsContext()) { supplier = db.DispatchSuppliers.IncludeAll("Country", "State", "State.Country", "Suburb", "Suburb.Country", "Suburb.State", "Suburb.State.Country").Where(s => s.Id == supplier.Id).SingleOrDefault(); return new EntityResponse<DispatchSupplier>(supplier); } } catch (Exception ex) { StringBuilder builder = new StringBuilder(); builder.AppendLine(ex.Message); if (ex.InnerException != null) { builder.AppendLine(ex.InnerException.Message); if (ex.InnerException.InnerException != null) builder.AppendLine(ex.InnerException.InnerException.Message); } return new EntityResponse<DispatchSupplier>(builder.ToString()); } }
public bool DeclineBooking(int bookingId) { try { using (var db = new LomsContext()) { db.Connection.Open(); using (var transaction = db.Connection.BeginTransaction()) { var booking = GetBooking(db, bookingId); if (booking.Status != BookingStatus.Fare || booking.Status != BookingStatus.Pending) return false; booking.ClearFareInfo(); booking.Status = BookingStatus.Declined; booking.ExpiryTime = null; db.Bookings.ApplyChanges(booking); db.SaveChanges(); transaction.Commit(); return true; } } } catch { } return false; }
public DispatchUser SaveWorldwideUser(DispatchUser user, byte[] imageBytes, bool deleteImage) { int managerId = int.Parse(((FormsIdentity)(HttpContext.Current.User.Identity)).Ticket.UserData); using (var scope = new TransactionScope()) using (var db = new LomsContext()) { if (user.Id == 0) { user.Login = user.FirstName[0] + user.LastName; var staffManager = (from m in db.DispatchUsers where m.Id == managerId select m).Single(); user.CreatedBy = staffManager.FirstName + " " + staffManager.LastName; user.CreatedDate = DateTime.UtcNow; } if (user.Id == 0) { if (user.Id == 0 && string.IsNullOrEmpty(user.Pwd)) user.Pwd = "123456!"; MembershipCreateStatus ret; MembershipUser membershipUser = Membership.CreateUser(user.Login, user.Pwd, user.Email, "Who am I?", "I", true, null, out ret); if (ret != MembershipCreateStatus.Success) throw new ApplicationException(ret.ToString()); user.AspNetUserId = (Guid)membershipUser.ProviderUserKey; } else if (!string.IsNullOrEmpty(user.Pwd)) { MembershipUser membershipUser = Membership.GetUser(user.Login); string tempPwd = membershipUser.ResetPassword(); membershipUser.ChangePassword(tempPwd, user.Pwd); } if (!Roles.IsUserInRole(user.Login, RoleName.DispatchUser)) Roles.AddUserToRole(user.Login, RoleName.DispatchUser); if (user.Role == DispatchUserRole.Manager && !Roles.IsUserInRole(user.Login, RoleName.DispatchManager)) Roles.AddUserToRole(user.Login, RoleName.DispatchManager); else if (user.Role != DispatchUserRole.Manager && Roles.IsUserInRole(user.Login, RoleName.DispatchManager)) Roles.RemoveUserFromRole(user.Login, RoleName.DispatchManager); db.DispatchUsers.ApplyChanges(user); db.SaveChanges(); user = db.DispatchUsers.IncludeAll("Suburb", "Suburb.Country", "Suburb.State", "Suburb.State.Country") .FirstOrDefault(a => a.Id == user.Id); scope.Complete(); return user; } }
public TimeSpan? ExtendBookingExpiryTime(int bookingId, int minutes) { try { using (var db = new LomsContext()) { db.Connection.Open(); using (var transaction = db.Connection.BeginTransaction()) { var booking = db.Bookings.FirstOrDefault(b => b.Id == bookingId); if (booking.Status != BookingStatus.Fare) return null; booking.ExpiryTime = booking.ExpiryTime.Value.AddMinutes(minutes); db.Bookings.ApplyChanges(booking); db.SaveChanges(); transaction.Commit(); return booking.ExpiryTime - DateTime.UtcNow; } } } catch { } return null; }
public ActivateClientAndLoginResponse ActivateClientWithPassword(Guid guid, string pwd) { try { using (var scope = new TransactionScope()) using (var db = new LomsContext()) { var activation = db.AssociationUserActivations.FirstOrDefault(a => a.Guid == guid); if (activation == null) return new ActivateClientAndLoginResponse("Wrong activation guid!"); db.AssociationUserActivations.DeleteObject(activation); db.SaveChanges(); var user = db.AssociationUsers.Single(u => u.Id == activation.UserId); if (user.AspNetUserId != null) { //update membership var userMembership = Membership.GetUser(user.AspNetUserId); userMembership.IsApproved = true; Membership.UpdateUser(userMembership); } else { //create membership var userMembership = Membership.CreateUser(user.Email, pwd, user.Email); Guid aspNetUserId = (Guid)userMembership.ProviderUserKey; //add role if (!Roles.RoleExists(RoleName.Client)) Roles.CreateRole(RoleName.Client); Roles.AddUserToRole(user.Email, RoleName.Client); user.AspNetUserId = aspNetUserId; db.AssociationUsers.ApplyChanges(user); db.SaveChanges(); } var isAuthenticatedResponse = _manager.ClientSignIn(user.Email, pwd, false); scope.Complete(); if (!isAuthenticatedResponse.IsAuthenticated) return new ActivateClientAndLoginResponse() { IsAuthenticatedResponse = isAuthenticatedResponse, Error = "Authentication failed." }; else return new ActivateClientAndLoginResponse() { IsAuthenticatedResponse = isAuthenticatedResponse }; } } catch (Exception ex) { StringBuilder builder = new StringBuilder(); builder.AppendLine(ex.Message); if (ex.InnerException != null) { builder.AppendLine(ex.InnerException.Message); if (ex.InnerException.InnerException != null) builder.AppendLine(ex.InnerException.InnerException.Message); } return new ActivateClientAndLoginResponse(builder.ToString()); } }
public BookingResponse SaveBookingFareType(int bookingId, FareType fareType) { try { using (var db = new LomsContext()) { var booking = GetBooking(db, bookingId); booking.FareType = fareType; var promotionId = booking.FareInfo.Items.First(i => i.FareTypeId == (byte)fareType).PromotionId; booking.FarePromotionId = promotionId.HasValue ? promotionId.Value : 0; db.BookingPaymentItems.Where(p => p.BookingId == bookingId).ForEach(item => db.BookingPaymentItems.DeleteObject(item)); //remove charge info and incompleted credit card transactions var chargeInfo = db.BookingChargeInfoes.SingleOrDefault(ci => ci.BookingId == bookingId); if (chargeInfo != null) db.BookingChargeInfoes.DeleteObject(chargeInfo); db.BookingTransactionCreditCards.Where(p => p.BookingId == bookingId && p.OrderDateTime == null).ForEach(item => db.BookingTransactionCreditCards.DeleteObject(item)); db.Bookings.ApplyChanges(booking); db.SaveChanges(); booking = GetBooking2(db, bookingId); return new BookingResponse { Booking = booking }; } } catch (Exception ex) { var response = new BookingResponse(); response.AddError("Response", ex.ToString()); return response; } }
public IsAuthenticatedResponse ChangeClientPassword(Guid guid, string pwd) { try { using (var db = new LomsContext()) { db.Connection.Open(); using (var transaction = db.Connection.BeginTransaction()) { var reset = db.AssociationUserPasswordResets.SingleOrDefault(r => r.Guid == guid); if (reset == null || reset.Time < DateTime.UtcNow) return new IsAuthenticatedResponse("Cannot change password."); var user = db.AssociationUsers.SingleOrDefault(u => u.Id == reset.AssociationUserId); var membershipUser = Membership.GetUser(user.Email); string tempPwd = membershipUser.ResetPassword(); membershipUser.ChangePassword(tempPwd, pwd); db.AssociationUserPasswordResets.DeleteObject(reset); db.SaveChanges(); var response = _manager.ClientSignIn(user.Email, pwd, false); transaction.Commit(); return response; } } } catch (Exception ex) { return new IsAuthenticatedResponse(ex.ToString()); } }
public SaveBookingPassengerInfoResponse SaveBookingPassengerInfo(int bookingId, int primaryPassengerId, BookingPassengerInfo info) { try { using (var db = new LomsContext()) { var booking = db.Bookings.FirstOrDefault(b => b.Id == bookingId); if (booking.PrimaryPassengerId != primaryPassengerId) { if (booking.CreatorId != primaryPassengerId) booking.PrimaryPassengerId = primaryPassengerId; else booking.PrimaryPassengerId = null; db.Bookings.ApplyChanges(booking); } info.RemovedAdults.ForEach(i => { db.BookingPassengerInfoAdults.Attach(i); db.BookingPassengerInfoAdults.DeleteObject(i); }); info.RemovedChilds.ForEach(i => { db.BookingPassengerInfoChilds.Attach(i); db.BookingPassengerInfoChilds.DeleteObject(i); }); info.RemovedInfants.ForEach(i => { db.BookingPassengerInfoInfants.Attach(i); db.BookingPassengerInfoInfants.DeleteObject(i); }); db.BookingPaymentItems.Where(p => p.BookingId == bookingId).ForEach(item => db.BookingPaymentItems.DeleteObject(item)); //remove charge info and incompleted credit card transactions var chargeInfo = db.BookingChargeInfoes.SingleOrDefault(ci => ci.BookingId == bookingId); if (chargeInfo != null) db.BookingChargeInfoes.DeleteObject(chargeInfo); db.BookingTransactionCreditCards.Where(p => p.BookingId == bookingId && p.OrderDateTime == null).ForEach(item => db.BookingTransactionCreditCards.DeleteObject(item)); db.BookingPassengerInfoes.ApplyChanges(info); db.SaveChanges(); } using (var db = new LomsContext()) { var response = new SaveBookingPassengerInfoResponse(); response.PassengerInfo = db.BookingPassengerInfoes.IncludeAll("Adults", "Childs", "Infants").FirstOrDefault(b => b.BookingId == bookingId); response.ProvisionInfo = db.BookingProvisionInfoes.FirstOrDefault(b => b.BookingId == bookingId); return response; } } catch (Exception ex) { var response = new SaveBookingPassengerInfoResponse(); response.AddError("Response", ex.ToString()); return response; } }
public string RegisterClient(ClientRegistrationRequest request) { try { using (var scope = new TransactionScope()) using (var db = new LomsContext()) { var email = request.Email.Trim().ToLower(); //check id user with such email existed already var count = (from u in db.AssociationUsers where u.AssociationId == CurrentAssociationId && u.Email == email select u).Count(); if (count != 0) return "User with such email is already registered!"; //create membership MembershipCreateStatus status; var userMembership = Membership.CreateUser(email, request.Password, email, "Am i client?", "Yes", false, out status); switch (status) { case MembershipCreateStatus.Success: break; //case MembershipCreateStatus.InvalidPassword: // throw new ApplicationException("Invalid password."); default: throw new ApplicationException("Cannot create user account.", new ApplicationException(status.ToString())); } Guid aspNetUserId = (Guid)userMembership.ProviderUserKey; //add role if (!Roles.RoleExists(RoleName.Client)) Roles.CreateRole(RoleName.Client); Roles.AddUserToRole(email, RoleName.Client); //create user AssociationUser user = new AssociationUser(); user.AssociationId = CurrentAssociationId; user.CountryId = request.CountryId; user.Email = email; //name user.Prefix = NamePrefix.All.FirstOrDefault(p => p.Id == request.NamePrefixId); user.FirstName = request.FirstName.ToUpper(); user.LastName = request.LastName.ToUpper(); //phone user.OfficePhone = request.OfficePhone; user.MobilePhone = request.MobilePhone; user.HomePhone = request.HomePhone; user.DefaultPhoneType = request.DefaultPhoneType; user.IsTravelAgency = request.IsTravelAgency; user.PositionTitle = request.Position; if (user.IsTravelAgency) user.IataNumber = request.IataNumber.ToUpper(); user.CreatedTime = user.LastUpdatedTime = DateTime.UtcNow; user.AspNetUserId = aspNetUserId; db.AssociationUsers.ApplyChanges(user); db.SaveChanges(); //home address AssociationUserAddress homeAddress = new AssociationUserAddress(); homeAddress.Nickname = user.FullName + " HOME"; homeAddress.AssociationUserId = user.Id; homeAddress.Type = AddressType.Home; homeAddress.CountryId = user.CountryId; //work address AssociationUserAddress workAddress = new AssociationUserAddress(); workAddress.Nickname = user.FullName + " WORK"; workAddress.AssociationUserId = user.Id; workAddress.CountryId = user.CountryId; workAddress.Type = AddressType.Work; workAddress.BusinessName = request.BusinessName.ToUpper(); workAddress.BuildingName = request.BuildingName.ToUpper(); workAddress.Address1 = request.Address1.ToUpper(); workAddress.Address2 = request.Address2.ToUpper(); if (request.SuburbId != 0) { workAddress.CountryId = null; workAddress.StateId = null; workAddress.SuburbId = request.SuburbId; } else { if (request.StateId != 0) { workAddress.CountryId = null; workAddress.StateId = request.StateId; workAddress.SuburbId = null; } workAddress.SuburbName = request.SuburbName.ToUpper(); workAddress.SuburbCode = request.SuburbCode.ToUpper(); } db.AssociationUserAddresses.ApplyChanges(homeAddress); db.AssociationUserAddresses.ApplyChanges(workAddress); db.SaveChanges(); AssociationUserActivation activation = new AssociationUserActivation(); activation.UserId = user.Id; activation.Guid = Guid.NewGuid(); activation.ExpiryTime = DateTime.UtcNow.AddHours(2.0); //expiry db.AssociationUserActivations.ApplyChanges(activation); db.SaveChanges(); var emailProvider = db.AssociationEmails.FirstOrDefault(e => e.AssociationId == CurrentAssociationId); if (emailProvider != null) { var association = db.Associations.FirstOrDefault(a => a.Id == CurrentAssociationId); var uri = HttpContext.Current.Request.Url; string baseUrl = String.Format("{0}://{1}:{2}", uri.Scheme, uri.Host ?? "80", uri.Port); string activtionLink = Path.Combine(baseUrl + string.Format("/#Activation/{0}", activation.Guid.ToString("D"))); string contactUsLink = Path.Combine(baseUrl + "/#Contact"); var emailTemplate = new EmailTemplate("OnlineRegistrationActivation"); emailTemplate["UserName"] = user.FullName.ToUpper(); emailTemplate["AssociationName"] = association.Name.ToUpper(); emailTemplate["ActivationLink"] = activtionLink; emailTemplate["ContactUsLink"] = contactUsLink; var avBody = AlternateView.CreateAlternateViewFromString(emailTemplate.Html, null, MediaTypeNames.Text.Html); emailProvider.SendMail(user.Email, association.Name + " Account activation", emailTemplate.Txt, null, avBody, true); } scope.Complete(); } return null; } catch (Exception ex) { StringBuilder builder = new StringBuilder(); builder.AppendLine(ex.Message); if (ex.InnerException != null) { builder.AppendLine(ex.InnerException.Message); if (ex.InnerException.InnerException != null) builder.AppendLine(ex.InnerException.InnerException.Message); } return builder.ToString(); } }
public SaveBookingProvisionInfoResponse SaveBookingProvisionInfo(int bookingId, BookingProvisionInfo info) { try { using (var db = new LomsContext()) { db.BookingProvisionInfoes.ApplyChanges(info); db.BookingPaymentItems.Where(p => p.BookingId == bookingId).ForEach(item => db.BookingPaymentItems.DeleteObject(item)); //remove charge info and incompleted credit card transactions var chargeInfo = db.BookingChargeInfoes.SingleOrDefault(ci => ci.BookingId == bookingId); if (chargeInfo != null) db.BookingChargeInfoes.DeleteObject(chargeInfo); db.BookingTransactionCreditCards.Where(p => p.BookingId == bookingId && p.OrderDateTime == null).ForEach(item => db.BookingTransactionCreditCards.DeleteObject(item)); db.SaveChanges(); var response = new SaveBookingProvisionInfoResponse(); response.PaymentInfo = db.BookingPayments.IncludeAll("CreditCard", "Items").FirstOrDefault(b => b.BookingId == bookingId); return response; } } catch (Exception ex) { var response = new SaveBookingProvisionInfoResponse(); response.AddError("Response", ex.ToString()); return response; } }
public void SendQuoteToUser(int bookingId, TimeSpan timeToExpire, BookingFareInfo bookingFareInfo) { using (var db = new LomsContext()) { db.Connection.Open(); using (var transaction = db.Connection.BeginTransaction()) { var bookingQuote = db.BookingQuotations.Single(q => q.BookingId == bookingId); bookingQuote.Status = QuotationStatus.Sent; db.BookingQuotations.ApplyChanges(bookingQuote); var booking = db.Bookings.IncludeAll("FareInfo", "FareInfo.Currency", "FareInfo.Items").Single(b => b.Id == bookingId); booking.Status = BookingStatus.Fare; booking.ExpiryTime = DateTime.UtcNow + timeToExpire; //update fare info prices booking.FareInfo.Price = bookingFareInfo.Price; for (int i = 0; i < 5; i++) { var item = booking.FareInfo.Items[i]; item.Price = (decimal)Math.Round((double)bookingFareInfo.Items[i].Price * item.Margin / 100.0, 4); } db.Bookings.ApplyChanges(booking); db.SaveChanges(); transaction.Commit(); } } }
public GetAllowedPaymentMehodResponse GetAllowedPaymentMehod(int bookingId) { try { using (var db = new LomsContext()) { var booking = GetBookingWithChargeInfo(db, bookingId); if (booking.OriginalId == 0 || booking.TransactionCreditCards.IsEmpty()) return new GetAllowedPaymentMehodResponse() { PaymentMehod = PaymentMehod.Any, ChargeInfo = booking.ChargeInfo }; var originalBooking = GetBookingWithChargeInfo(db, booking.OriginalId); decimal amount = originalBooking.ChargeInfo.Amount - booking.ChargeInfo.Amount; if (amount > 0) { //remove incompleted transations booking.TransactionCreditCards.Where(item => item.OrderDateTime == null).ForEach(item => db.BookingTransactionCreditCards.DeleteObject(item)); var newTransactionCreditCards = new List<BookingTransactionCreditCard>(); foreach (var transaction in booking.TransactionCreditCards.Where(item => item.OrderDateTime != null).OrderByDescending(t => t.OrderDateTime)) { if (transaction.OrderAmount - transaction.RefundedAmount <= 0) continue; //create refund transaction var newTransaction = new BookingTransactionCreditCard(); newTransaction.BookingId = booking.Id; newTransaction.TypeId = transaction.TypeId; newTransaction.Holder = transaction.Holder; newTransaction.ExpiryMonth = transaction.ExpiryMonth; newTransaction.ExpiryYear = transaction.ExpiryYear; newTransaction.PaymentApi = null; newTransaction.OrderType = OrderType.Refund; newTransaction.OriginalOrderNumber = transaction.OrderNumber; newTransaction.OrderDateTime = null; newTransaction.OrderAmount = amount > transaction.OrderAmount ? transaction.OrderAmount : amount; db.BookingTransactionCreditCards.ApplyChanges(newTransaction); transaction.RefundedAmount += newTransaction.OrderAmount; db.BookingTransactionCreditCards.ApplyChanges(transaction); db.SaveChanges(); if (transaction.Info == null) transaction.Info = db.BookingTransactionCreditCardInfoes.Single(i => i.CreditCardId == transaction.Id); var newTransactionCreditCardInfo = new BookingTransactionCreditCardInfo() { CreditCardId = newTransaction.Id, Number = transaction.Info.Number, CVC = transaction.Info.CVC }; db.BookingTransactionCreditCardInfoes.ApplyChanges(newTransactionCreditCardInfo); db.SaveChanges(); newTransaction.Number = AssociationUserCreditCard.ObfuscateCreditCardNumber(newTransactionCreditCardInfo.Number); newTransactionCreditCards.Add(newTransaction); amount -= newTransaction.OrderAmount; if (amount == 0) break; } return new GetAllowedPaymentMehodResponse() { PaymentMehod = PaymentMehod.SkipDueToRefundOrSamePrice, ChargeInfo = booking.ChargeInfo, NewTransactionCreditCards = newTransactionCreditCards }; } else if (amount == 0) return new GetAllowedPaymentMehodResponse() { PaymentMehod = PaymentMehod.SkipDueToRefundOrSamePrice, ChargeInfo = booking.ChargeInfo }; else return new GetAllowedPaymentMehodResponse() { PaymentMehod = PaymentMehod.CreditCard, ChargeInfo = booking.ChargeInfo }; } } catch (Exception ex) { var response = new GetAllowedPaymentMehodResponse(); response.AddError("Response", ex.ToString()); return response; } }
protected void btnActivate_Click(object sender, EventArgs e) { string guidStr = Page.RouteData.Values["guid"] as string; Guid guid; if (guidStr == null || !Guid.TryParseExact(guidStr, "D", out guid)) { multiView1.SetActiveView(viewError); lblError.Text = "Wrong activation guid!"; return; } else { using (var db = new LomsContext()) { var activation = db.AssociationUserActivations.FirstOrDefault(a => a.Guid == guid); if (activation == null) { multiView1.SetActiveView(viewError); lblError.Text = "Wrong activation guid!"; return; } //validate password string pwd = txtPassword.Text.Trim(); string pwd2 = txtConfirmPassword.Text.Trim(); bool notValidated = false; if (string.IsNullOrEmpty(pwd)) { notValidated |= lblPasswordNote.Visible = true; lblComfirmPasswordNote.Text = "Password is required."; } if (string.IsNullOrEmpty(pwd2)) { notValidated |= lblComfirmPasswordNote.Visible = true; lblComfirmPasswordNote.Text = "Confirm Password is required."; } else if (pwd != pwd2) { notValidated |= lblComfirmPasswordNote.Visible = true; lblComfirmPasswordNote.Text = "Confirm Password does not match to Password."; } notValidated |= lblTermsNote.Visible = !checkTermsConfirmed.Checked; notValidated |= lblAgeNote.Visible = !checkAge16Confirmed.Checked; if (notValidated) return; var user = db.AssociationUsers.First(u => u.Id == activation.UserId); Guid aspNetUserId = (Guid)Membership.CreateUser(user.Email, pwd, user.Email).ProviderUserKey; //add role if (!Roles.RoleExists(RoleName.Client)) Roles.CreateRole(RoleName.Client); Roles.AddUserToRole(user.Email, RoleName.Client); user.AspNetUserId = aspNetUserId; db.AssociationUsers.ApplyChanges(user); db.AssociationUserActivations.DeleteObject(activation); //create membership var userMembership = Membership.GetUser(user.AspNetUserId); userMembership.IsApproved = true; db.SaveChanges(); multiView1.SetActiveView(viewSuccess); lblInfo2.Visible = lblInfo21.Visible = lblInfo3.Visible = lblInfo4.Visible = true; //lblInfo.Text = string.Format("Congratulations {0} {1}!", user.FirstName.ToUpper(), user.LastName.ToUpper()); lblInfo.Text = string.Format("Congratulations!"); lblInfo2.Text = string.Format("Your account profile is now ACTIVE"); lblInfo21.Text = ""; //lblInfo21.Text = string.Format("Your password has been sent to {0}.", user.Email); lblInfo3.Text = "We look forward to providing you with our on-time guaranteed services for all your journeys."; lblInfo4.Text = "Once again if you require any further assistance feel free to contact us."; } } }
public SaveBookingPaymentInfoResponse SaveBookingPaymentInfo(int bookingId, BookingPayment info) { var response = new SaveBookingPaymentInfoResponse(); try { using (var db = new LomsContext()) { var booking = GetBookingWithChargeInfo(db, bookingId); response.ChargeInfo = booking.ChargeInfo; var payment = db.BookingPayments.IncludeAll("CreditCard", "CreditCard.Info", "CreditCard.Address", "BillingAccount", "Items").FirstOrDefault(b => b.BookingId == bookingId); if (payment == null) payment = new BookingPayment() { BookingId = bookingId }; payment.AssociationUserId = info.AssociationUserId; db.BookingPayments.ApplyChanges(payment); db.SaveChanges(); if (info.CreditCard != null) { if (payment.BillingAccount != null) db.BookingPaymentBillingAccounts.DeleteObject(payment.BillingAccount); if (payment.CreditCard == null) payment.CreditCard = new BookingPaymentCreditCard() { CreditCardId = bookingId }; if (info.CreditCard.SavedCreditCardId != 0) //saved card { var savedCreditCard = db.AssociationUserCreditCards.IncludeAll("Info").FirstOrDefault(cc => cc.Id == info.CreditCard.SavedCreditCardId); payment.CreditCard.TypeId = savedCreditCard.TypeId; payment.CreditCard.Holder = savedCreditCard.Holder; payment.CreditCard.ExpiryMonth = savedCreditCard.ExpiryMonth; payment.CreditCard.ExpiryYear = savedCreditCard.ExpiryYear; payment.CreditCard.SavedCreditCardId = info.CreditCard.SavedCreditCardId; payment.CreditCard.SavedCreditCardNickname = null; payment.CreditCard.SavedCrediCardIsDefaultBilling = info.CreditCard.SavedCrediCardIsDefaultBilling; db.BookingPaymentCreditCards.ApplyChanges(payment.CreditCard); db.SaveChanges(); if (payment.CreditCard.Info == null) payment.CreditCard.Info = new BookingPaymentCreditCardInfo(); payment.CreditCard.Info.CardId = payment.CreditCard.CreditCardId; payment.CreditCard.Info.Number = savedCreditCard.Info.Number; payment.CreditCard.Info.CVC = savedCreditCard.Info.CVC; db.BookingPaymentCreditCardInfoes.ApplyChanges(payment.CreditCard.Info); db.SaveChanges(); } else //new credit card { payment.CreditCard.TypeId = info.CreditCard.TypeId; payment.CreditCard.Holder = info.CreditCard.Holder; payment.CreditCard.ExpiryMonth = info.CreditCard.ExpiryMonth; payment.CreditCard.ExpiryYear = info.CreditCard.ExpiryYear; payment.CreditCard.SavedCreditCardId = info.CreditCard.SavedCreditCardId; payment.CreditCard.SavedCreditCardNickname = info.CreditCard.SavedCreditCardNickname; payment.CreditCard.SavedCrediCardIsDefaultBilling = info.CreditCard.SavedCrediCardIsDefaultBilling; db.BookingPaymentCreditCards.ApplyChanges(payment.CreditCard); db.SaveChanges(); if (payment.CreditCard.Info == null) payment.CreditCard.Info = new BookingPaymentCreditCardInfo(); payment.CreditCard.Info.CardId = payment.CreditCard.CreditCardId; payment.CreditCard.Info.Number = info.CreditCard.Number; payment.CreditCard.Info.CVC = info.CreditCard.CVC; db.BookingPaymentCreditCardInfoes.ApplyChanges(payment.CreditCard.Info); db.SaveChanges(); } //remove old transactions db.BookingTransactionCreditCards.Where(p => p.BookingId == bookingId && p.OrderDateTime == null).ForEach(item => db.BookingTransactionCreditCards.DeleteObject(item)); db.BookingTransactionBillingAccounts.Where(p => p.BillingAccountId == bookingId).ForEach(item => db.BookingTransactionBillingAccounts.DeleteObject(item)); //create transaction decimal amount = booking.ChargeInfo.Amount; bool existedPaidTransactions = booking.TransactionCreditCards.Where(p => p.BookingId == bookingId && p.OrderDateTime != null).HasItems(); if (booking.OriginalId != 0 && existedPaidTransactions) { var originalBooking = GetBookingWithChargeInfo(db, booking.OriginalId); amount = amount - originalBooking.ChargeInfo.Amount; } var transactionCreditCard = new BookingTransactionCreditCard(); transactionCreditCard.BookingId = booking.Id; transactionCreditCard.TypeId = payment.CreditCard.TypeId; transactionCreditCard.Holder = payment.CreditCard.Holder; transactionCreditCard.ExpiryMonth = payment.CreditCard.ExpiryMonth; transactionCreditCard.ExpiryYear = payment.CreditCard.ExpiryYear; transactionCreditCard.PaymentApi = null; transactionCreditCard.OrderType = OrderType.Capture; transactionCreditCard.OrderNumber = null; transactionCreditCard.OrderDateTime = null; transactionCreditCard.OrderAmount = amount; db.BookingTransactionCreditCards.ApplyChanges(transactionCreditCard); db.SaveChanges(); var transactionCreditCardInfo = new BookingTransactionCreditCardInfo() { CreditCardId = transactionCreditCard.Id, Number = payment.CreditCard.Info.Number, CVC = payment.CreditCard.Info.CVC }; db.BookingTransactionCreditCardInfoes.ApplyChanges(transactionCreditCardInfo); db.SaveChanges(); transactionCreditCard.Number = AssociationUserCreditCard.ObfuscateCreditCardNumber(transactionCreditCardInfo.Number); response.NewTransactionCreditCard = transactionCreditCard; } else if (info.BillingAccount != null) { if (payment.CreditCard != null) db.BookingPaymentCreditCards.DeleteObject(payment.CreditCard); if (payment.BillingAccount == null) payment.BillingAccount = new BookingPaymentBillingAccount() { BillingAccountId = bookingId }; if (info.BillingAccount.SavedBillingAccountId != 0) //saved Billing Account { var savedBillingAccount = db.AssociationUserBillingAccounts.FirstOrDefault(cc => cc.Id == info.BillingAccount.SavedBillingAccountId); payment.BillingAccount.ChargeBackId = savedBillingAccount.BillingAccountId; payment.BillingAccount.BillingCode = savedBillingAccount.BillingCode; payment.BillingAccount.Email = savedBillingAccount.Email; payment.BillingAccount.ContactPerson = savedBillingAccount.ContactPerson; payment.BillingAccount.ContactNumber = savedBillingAccount.ContactNumber; payment.BillingAccount.SavedBillingAccountNickname = null; } else //new Billing Account { payment.BillingAccount.ChargeBackId = info.BillingAccount.ChargeBackId; payment.BillingAccount.BillingCode = info.BillingAccount.BillingCode; payment.BillingAccount.Email = info.BillingAccount.Email; payment.BillingAccount.ContactPerson = info.BillingAccount.ContactPerson; payment.BillingAccount.ContactNumber = info.BillingAccount.ContactNumber; payment.BillingAccount.SavedBillingAccountNickname = info.BillingAccount.SavedBillingAccountNickname; } payment.BillingAccount.SavedBillingAccountId = info.BillingAccount.SavedBillingAccountId; payment.BillingAccount.SavedBillingAccountIsDefaultBilling = info.BillingAccount.SavedBillingAccountIsDefaultBilling; db.BookingPaymentBillingAccounts.ApplyChanges(payment.BillingAccount); db.SaveChanges(); //remove old transactions db.BookingTransactionCreditCards.Where(p => p.BookingId == bookingId && p.OrderDateTime == null).ForEach(item => db.BookingTransactionCreditCards.DeleteObject(item)); //create transaction var transactionBillingAccount = db.BookingTransactionBillingAccounts.SingleOrDefault(t => t.BillingAccountId == bookingId); if (transactionBillingAccount == null) transactionBillingAccount = new BookingTransactionBillingAccount() { BillingAccountId = bookingId }; transactionBillingAccount.ChargeBackId = payment.BillingAccount.ChargeBackId; transactionBillingAccount.BillingCode = payment.BillingAccount.BillingCode; transactionBillingAccount.Email = payment.BillingAccount.Email; transactionBillingAccount.ContactPerson = payment.BillingAccount.ContactPerson; transactionBillingAccount.ContactNumber = payment.BillingAccount.ContactNumber; db.BookingTransactionBillingAccounts.ApplyChanges(transactionBillingAccount); db.SaveChanges(); response.NewTransactionBillingAccount = transactionBillingAccount; } } using (var db = new LomsContext()) { response.PaymentInfo = db.BookingPayments.IncludeAll("CreditCard", "CreditCard.Info", "CreditCard.Address", "BillingAccount", "BillingAccount.ChargeBack", "BillingAccount.ChargeBack.Country", "Items").FirstOrDefault(b => b.BookingId == bookingId); if (response.PaymentInfo.CreditCard != null) { if (response.PaymentInfo.CreditCard.Info == null) response.PaymentInfo.CreditCard.Info = db.BookingPaymentCreditCardInfoes.SingleOrDefault(i => i.CardId == bookingId); response.PaymentInfo.CreditCard.Number = AssociationUserCreditCard.ObfuscateCreditCardNumber(response.PaymentInfo.CreditCard.Info.Number); response.PaymentInfo.CreditCard.Info = null; response.PaymentInfo.CreditCard.AcceptChanges(); } response.NewTransactionBillingAccount = db.BookingTransactionBillingAccounts.IncludeAll("ChargeBack", "ChargeBack.Country").SingleOrDefault(t => t.BillingAccountId == bookingId); return response; } } catch (Exception ex) { response = new SaveBookingPaymentInfoResponse(); response.AddError("Response", ex.ToString()); return response; } }