public IEnumerable<CitySupplierInfo> GetCitySuppliers(int cityId) { using (var db = new LomsContext()) { var suppliers = from a in db.DispatchSuppliers.IncludeAll("Country", "State", "State.Country", "Suburb", "Suburb.Country", "Suburb.State", "Suburb.State.Country") join ac in db.DispatchSupplierCities on a.Id equals ac.SupplierId where ac.CityId == cityId orderby a.Name select a; var citySupplierInfos = new List<CitySupplierInfo>(); foreach (var supplier in suppliers.ToList()) { if (supplier.CountryId != null && supplier.Country == null) supplier.Country = db.Countries.SingleOrDefault(c => c.Id == supplier.CountryId); else if (supplier.StateId != null && supplier.State == null) supplier.State = db.States.Include("Country").SingleOrDefault(s => s.Id == supplier.StateId); else if (supplier.SuburbId != null && supplier.Suburb == null) supplier.Suburb = db.Suburbs.IncludeAll("State", "State.Country", "Country").SingleOrDefault(s => s.Id == supplier.SuburbId); var info = new CitySupplierInfo() { Supplier = supplier }; info.Manager = db.DispatchSupplierUsers.FirstOrDefault(u => u.SupplierId == supplier.Id && u.RoleId == (int)SupplierUserRole.Manager); var supplierCity = db.DispatchSupplierCities.IncludeAll("VehicleTypes", "VehicleTypes.VehicleType").SingleOrDefault(c => c.SupplierId == supplier.Id && c.CityId == cityId); info.CityVehicleTypes = supplierCity.VehicleTypes; citySupplierInfos.Add(info); } return citySupplierInfos; } }
public DispatchWorldwide GetWorldwide() { using (var db = new LomsContext()) { return db.DispatchWorldwides.IncludeAll("Suburb", "Suburb.Country", "Suburb.State", "Suburb.State.Country").FirstOrDefault(); } }
public Association GetAssociation() { using (var db = new LomsContext()) { return db.Associations.SingleOrDefault(a => a.Id == CurrentAssociationId); } }
public IEnumerable<AssociationUserCreditCard> GetCreditCards(int profileId, SearchRequest searchRequest) { using (var db = new LomsContext()) { var query = db.AssociationUserCreditCards.IncludeAll("Info") .Where(a => a.AssociationUserId == profileId); if (!string.IsNullOrWhiteSpace(searchRequest.SearchFilterValue)) { if (searchRequest.SearchFilter == "Nickname") query = from card in query where card.Nickname.Contains(searchRequest.SearchFilterValue) select card; } var cards = query.OrderBy(a => a.Nickname).ToList(); cards.ForEach(card => { card.Number = ObfuscateCreditCardNumber(card.Info.Number); card.Info = null; card.AcceptChanges(); }); return cards; } }
public static double GetRate(LomsContext db, Booking booking, DebugWriter debugInfoWriter) { double extras; bool autoPending = false; double price = 0.0; try { price = GetBaseRateWithAdminFees(db, booking, debugInfoWriter, out autoPending, out extras); if (price == 0.0 || autoPending) return 0.0; } catch (Exception ex) { debugInfoWriter.WriteLine("Exception during GetBaseRateWithAdminFees!"); debugInfoWriter.WriteLine(ex.ToString()); return 0.0; } RateHelper.ApplyVehicleMargin(db, booking, debugInfoWriter, ref price); price += extras; RateHelper.ApplyHourZone(db, booking, debugInfoWriter, ref price); //RateHelper.ApplyEventMargin(db, booking, debugInfoWriter, ref price, ref autoPending, ref eventName); //if (autoPending) // return 0.0; return price; }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { 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; } var user = db.AssociationUsers.First(u => u.Id == pwdReset.AssociationUserId); lblUserWelcome.Text = string.Format("Welcome, {0}.", user.FullName.ToUpper()); multiView1.SetActiveView(viewPwd); } } } }
public IEnumerable<AssociationUserCreditCard> GetCreditCards(int profileId, SearchRequest searchRequest) { using (var db = new LomsContext()) { return GetCreditCards(db, profileId, searchRequest); } }
private IEnumerable<AssociationUserCreditCard> GetCreditCards(LomsContext db, int profileId, SearchRequest searchRequest) { var query = db.AssociationUserCreditCards.IncludeAll("Info") .Where(a => a.AssociationUserId == profileId); if (searchRequest != null && !string.IsNullOrWhiteSpace(searchRequest.SearchFilterValue)) { if (searchRequest.SearchFilter == "Nickname") query = from card in query where card.Nickname.Contains(searchRequest.SearchFilterValue) select card; } var cards = query.OrderBy(a => a.Nickname).ToList(); cards.ForEach(card => { card.Number = AssociationUserCreditCard.ObfuscateCreditCardNumber(card.Info.Number); card.Info = null; card.AcceptChanges(); }); var defaultBilling = db.AssociationUserDefaultBillings.SingleOrDefault(b => b.AssociationUserId == profileId); if (defaultBilling != null && defaultBilling.CreditCardId.HasValue) { var card = cards.Single(i => i.Id == defaultBilling.CreditCardId); card.IsDefaultBilling = true; } return cards; }
public static bool AllocateVehicle(LomsContext db, Booking booking, bool isPhantom, StringBuilder debug) { int vehicleTypeId = booking.VehicleTypeId.Value; var pickUpTime = booking.PickUpTime.Value; int jorneyLength = 30; //min DateTime fromDate = pickUpTime.Date; DateTime toDate = pickUpTime.AddMinutes(jorneyLength).Date; int fromTime = (((int)pickUpTime.TimeOfDay.TotalMinutes) / 30) * 30; int toTime = (((int)pickUpTime.AddMinutes(jorneyLength).TimeOfDay.TotalMinutes) / 30) * 30; if (!CheckAvailability(db, booking.Id, booking.CityId, vehicleTypeId, fromDate, toDate, fromTime, toTime, isPhantom, debug)) return false; if (booking.AllocatedVehicle == null) booking.AllocatedVehicle = new BookingAllocatedVehicle() { BookingId = booking.Id }; booking.AllocatedVehicle.CityId = booking.CityId; booking.AllocatedVehicle.VehicleTypeId = vehicleTypeId; booking.AllocatedVehicle.From = fromDate.AddMinutes(fromTime); booking.AllocatedVehicle.To = toDate.AddMinutes(toTime); booking.AllocatedVehicle.IsPhantom = isPhantom; return true; }
public Booking GetBooking(int id) { using (var db = new LomsContext()) { return GetBooking(db, id); } }
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 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 string GetAssociationName() { using (var db = new LomsContext()) { return (from a in db.Associations where a.Id == CurrentAssociationId select a.Name).FirstOrDefault(); } }
public Association GetCurrentAssociation() { var associationId = (int)HttpContext.Current.Items["AssociationId"]; using (var db = new LomsContext()) { var association = db.Associations.Include("Country").FirstOrDefault(a => a.Id == associationId); return association; } }
public IEnumerable<DispatchUser> GetWorldwideUsers() { using (var db = new LomsContext()) { return db.DispatchUsers.IncludeAll("Country", "Suburb", "Suburb.Country", "Suburb.State", "Suburb.State.Country") .Where(u => u.RegionId == null && u.DistrictId == null) .ToList(); } }
public AssociationUser GetUser() { using (var db = new LomsContext()) { int currentUserId = CurrentUserId(); var user = db.AssociationUsers.IncludeAll("Country").FirstOrDefault(u => u.Id == currentUserId); return user; } }
public bool ChangePassword(int managerId, string pwd, string newPwd) { using (var db = new LomsContext()) { var manager = db.AssociationUsers.FirstOrDefault(m => m.Id == managerId); MembershipUser user = Membership.GetUser(manager.Email); return user.ChangePassword(pwd, newPwd); } }
public IEnumerable<Association> GetAssociations() { using (var db = new LomsContext()) { var query = from a in db.Associations orderby a.Name select a; return query.ToList(); } }
public Segator.Loms.Modules.Common.Entities.Country GetCurrentAssociationCountry() { var associationId = (int)HttpContext.Current.Items["AssociationId"]; using (var db = new LomsContext()) { var query = from a in db.Associations.Include("Country") where a.Id == associationId select a.Country; return query.SingleOrDefault(); } }
public IEnumerable<Country> GetAssociationCountries() { using (var db = new LomsContext()) { var query = from ac in db.AssociationCountries.Include("Country") where ac.AssociationId == CurrentAssociationId && ac.Country.StatusId == (byte)EntityStatus.Active orderby ac.Country.Name select ac.Country; return query.Distinct().OrderBy(c => c.Name).ToList(); } }
public GetBillingsResponse GetBillings(int profileId) { using (var db = new LomsContext()) { return new GetBillingsResponse { CreditCards = GetCreditCards(db, profileId, null), BillingAccounts = GetBillingAccounts(db, profileId), SavedBillingAccounts = GetUserBillingAccounts(db, profileId, null) }; } }
public IEnumerable<Country> GetCountries() { using (var db = new LomsContext()) { var query = from city in db.Cities.Include("Country") where city.Country.StatusId == (byte)EntityStatus.Active orderby city.Country.Name select city.Country; return query.Distinct().ToList(); } }
public IEnumerable<City> GetCities(int countryId) { using (var db = new LomsContext()) { var query = from c in db.Cities.Include("State").Include("Country") where c.CountryId == countryId && (c.Status == null || c.Status == (byte)EntityStatus.Active) orderby c.Name select c; return query.ToList(); } }
public bool ChangeStaffUserPassword(int staffUserId, string pwd, string newPwd) { using (var db = new LomsContext()) { if (!Roles.IsUserInRole(RoleName.StaffUser)) throw new SecurityException(); var manager = db.AssociationStaffUsers.FirstOrDefault(m => m.Id == staffUserId); MembershipUser user = Membership.GetUser(manager.Login); return user.ChangePassword(pwd, newPwd); } }
private static double GetBaseRateWithAdminFees(LomsContext db, Booking booking, DebugWriter debug, out bool autoPending, out double extras) { autoPending = false; extras = 0; //pick-up debug.WriteLine("Pick-Up:"); double extrasForPickUp; SubDivision subFrom = GetSubDivision(db, booking, booking.PickUpEndpoint, debug, out autoPending, out extrasForPickUp); if (subFrom == null || autoPending) return 0.0; Zone zoneFrom; Region regionFrom; debug.WriteSubDivisionInfo(db, subFrom, out zoneFrom, out regionFrom); if (extrasForPickUp != 0.0) debug.WriteLine("Airport Extras: {0:0.00}", extrasForPickUp); //drop-off debug.WriteLine(); debug.WriteLine("Drop-Off:"); double extrasForDropOff; SubDivision subTo = GetSubDivision(db, booking, booking.DropOffEndpoint, debug, out autoPending, out extrasForDropOff); if (subTo == null) return 0.0; Zone zoneTo; Region regionTo; debug.WriteSubDivisionInfo(db, subTo, out zoneTo, out regionTo); if (extrasForDropOff != 0.0) debug.WriteLine("Airport Extras: {0:0.00}", extrasForDropOff); debug.WriteLine(); SubDivisionRate baseRate = db.SubDivisionRates.FirstOrDefault(r => r.SubDivisionFromId == subFrom.Id && r.SubDivisionToId == subTo.Id); debug.WriteBaseRate(baseRate); if (baseRate == null) return 0.0; double price = 0.0; if (baseRate != null) { price = baseRate.Rate; //admin fees List<AdminFee> adminFees = GetAdminFees(db, booking, zoneFrom, regionFrom, zoneTo, regionTo); if (adminFees != null) foreach (var value in adminFees) price += baseRate.Rate * value.Margin / 100.0 + value.Fee; } extras = extrasForPickUp + extrasForDropOff; return price; }
public IEnumerable<State> GetStates(int countryId) { using (var db = new LomsContext()) { var query = from s in db.States.Include("Country") where s.CountryId == countryId orderby s.Name select s; return query.ToList(); } }
public static bool IsInnerJourney(LomsContext db, Booking booking) { if (!IsInner(db, booking.CityId, booking.PickUpEndpoint.Type, booking.PickUpEndpoint.SuburbId, booking.PickUpEndpoint.AirportId)) return false; if (!IsInner(db, booking.CityId, booking.DropOffEndpoint.Type, booking.DropOffEndpoint.SuburbId, booking.DropOffEndpoint.AirportId)) return false; foreach (BookingStop stop in booking.Stops) if (!IsInner(db, booking.CityId, stop.EndpointType, stop.SuburbId, stop.AirportId)) return false; return true; }
public bool IsEmailUnique(string email) { using (var db = new LomsContext()) { email = 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(); return count == 0; } }
public BreadcrumbsResponse GetBreadcrumbs(int creatorId, int primaryPassengerId) { using (var db = new LomsContext()) { var breadcrumbs = new BreadcrumbsResponse(); breadcrumbs.Creator = db.AssociationUsers.Single(u => u.Id == creatorId); if (primaryPassengerId != 0 && creatorId != primaryPassengerId) breadcrumbs.PrimaryPassenger = db.AssociationUsers.Single(u => u.Id == primaryPassengerId); return breadcrumbs; } }
private static bool CheckAvailability(LomsContext db, int bookingId, int cityId, int vehicleTypeId, DateTime fromDate, DateTime toDate, int fromTime, int toTime, bool isPhantom, StringBuilder debug) { for (DateTime date = fromDate; date <= toDate; date = date.AddDays(1)) { var template = db.VehicleAvailabilityTemplates.FirstOrDefault(t => t.CityId == cityId && t.VehicleTypeId == vehicleTypeId && t.StartDate <= date && date <= t.EndDate); if (template == null) { debug.AppendLine("Vehicle availability template cannot be found for " + date.ToString("dd MMM yyyy") + "."); return false; } int time1 = date == fromDate ? fromTime : 0; int time2 = date == toDate ? toTime : 24 * 60 - 30; for (int time = time1; time < time2; time += 30) { int totalVehicles; if (isPhantom) totalVehicles = template.GetPhantom(date.DayOfWeek, time); else totalVehicles = template.GetPending(date.DayOfWeek, time); var detail = db.VehicleAvailabilityTemplateDetails.FirstOrDefault(d => d.TemplateId == template.Id && d.Date == date && d.Time == time); if (detail != null) { if (isPhantom) totalVehicles = detail.Phantom; else totalVehicles = detail.Pending; } //get allocated DateTime t = date.AddMinutes(time); var bookedVehicles = db.BookingAllocatedVehicles.Count(v => v.BookingId != bookingId && v.CityId == cityId && v.VehicleTypeId == vehicleTypeId && v.From <= t && t < v.To && v.IsPhantom == isPhantom); int availableVehicles = totalVehicles - bookedVehicles; if (availableVehicles <= 0) { if (isPhantom) debug.AppendLine("No free phantoms on " + date.AddMinutes(time).ToString("dd MMM yyyy HH:mm") + "."); else debug.AppendLine("No free pending on " + date.AddMinutes(time).ToString("dd MMM yyyy HH:mm") + "."); return false; } } } return true; }