public static List<byte> GetDistinctTourDays() { using (SriLankaToursEntities db = new SriLankaToursEntities()) { return db.TourEntities.Select(x => x.NoOfDays).Distinct().ToList(); } }
internal static bool DeleteTourDay(int tourDayId) { try { bool status = false; using (SriLankaToursEntities context = new SriLankaToursEntities()) { TourDayEntity tour = context.TourDayEntities.FirstOrDefault(x => x.TourDayId == tourDayId); if (tour == null) throw new TourDayNotFoundException("Tour day not found"); context.TourDayEntities.Remove(tour); context.SaveChanges(); DeleteTourDayImages(tour.TourDayImage); status = true; } return status; } catch (Exception) { throw; } }
internal static TaxiServiceModel CreateTaxiService(TaxiServiceEntity service) { try { using (SriLankaToursEntities context = new SriLankaToursEntities()) { bool isServiceExists = context.TaxiServiceEntities.Any(x => (x.FromId == service.FromId) && (x.ToId == service.ToId) && (x.VehicleId == service.VehicleId)); if (isServiceExists) throw new TaxiServiceExistsException("Taxi service already exists"); context.TaxiServiceEntities.Add(service); context.SaveChanges(); vTaxiService view = context.vTaxiServices.First(x => x.ServiceId == service.ServiceId); Mapper.CreateMap<vTaxiService, TaxiServiceModel>(); return Mapper.Map<TaxiServiceModel>(view); } } catch (Exception) { throw; } }
internal static bool DeleteTaxiService(int serviceId) { try { bool status = false; using (SriLankaToursEntities context = new SriLankaToursEntities()) { TaxiServiceEntity entity = context.TaxiServiceEntities.Find(serviceId); if (entity == null) throw new TaxiServiceNotFoundException("Taxi service not found"); context.TaxiServiceEntities.Remove(entity); context.SaveChanges(); status = true; } return status; } catch (Exception) { throw; } }
/// <summary> /// Deletes given tour from database /// </summary> /// <param name="tourId">Id of the tour to delete</param> /// <returns>bool</returns> internal static bool DeleteTour(int tourId) { try { bool status = false; using (SriLankaToursEntities context = new SriLankaToursEntities()) { TourEntity tour = context.TourEntities.Find(tourId); if (tour == null) throw new TourNotFoundException("Tour not found"); context.TourEntities.Remove(tour); context.SaveChanges(); DeleteTourImages(tour.TourBannerImage); status = true; } return status; } catch (Exception) { throw; } }
internal static TourDayModel CreateTourDay(TourDayEntity tourDayEntity) { try { using (SriLankaToursEntities context = new SriLankaToursEntities()) { TourDayEntity tourDay = context.TourDayEntities.Find(tourDayEntity.TourId, tourDayEntity.Day); if (tourDay != null) throw new TourDayExistsException("Tour day you are trying to add already exists"); context.TourDayEntities.Add(tourDayEntity); context.SaveChanges(); vTourDay view = context.vTourDays.First(x => x.TourDayId == tourDayEntity.TourDayId); Mapper.CreateMap<vTourDay, TourModel>(); return Mapper.Map<TourDayModel>(view); } } catch (Exception) { throw; } }
internal static TourDayModel GetTourDay(int tourDayId) { try { using (SriLankaToursEntities context = new SriLankaToursEntities()) { vTourDay view = context.vTourDays.FirstOrDefault(x => x.TourDayId == tourDayId); Mapper.CreateMap<vTourDay, TourDayModel>(); return Mapper.Map<TourDayModel>(view); } } catch (Exception) { throw; } }
internal static TourModel CreateTour(TourEntity tourEntity) { try { using (SriLankaToursEntities context = new SriLankaToursEntities()) { context.TourEntities.Add(tourEntity); context.SaveChanges(); return GetTour(tourEntity.TourId); } } catch (Exception) { throw; } }
internal static UserModel GetUser(int userId) { try { using (SriLankaToursEntities context = new SriLankaToursEntities()) { vUser view = context.vUsers.First(x => x.UserId == userId); Mapper.CreateMap<vUser, UserModel>(); UserModel user = Mapper.Map<vUser, UserModel>(view); return user; } } catch (Exception) { throw; } }
internal static TaxiServiceModel GetTaxiService(int serviceId) { try { using (SriLankaToursEntities context = new SriLankaToursEntities()) { vTaxiService view = context.vTaxiServices.FirstOrDefault(x => x.ServiceId == serviceId); if (view == null) throw new TaxiServiceNotFoundException(); Mapper.CreateMap<vTaxiService, TaxiServiceModel>(); return Mapper.Map<TaxiServiceModel>(view); } } catch (Exception) { throw; } }
internal static bool AddTourCharges(IList<TourChargeEntity> entities) { try { bool isSuccess = false; using (SriLankaToursEntities context = new SriLankaToursEntities()) { foreach (var entity in entities) { context.TourChargeEntities.Add(entity); } context.SaveChanges(); isSuccess = true; } return isSuccess; } catch (Exception) { throw; } }
internal static IEnumerable<TaxiServiceModel> GetTaxiServices(bool includeHidden) { try { using (SriLankaToursEntities context = new SriLankaToursEntities()) { IEnumerable<vTaxiService> views = context.vTaxiServices.Where(x => (includeHidden == false ? x.Visible == true : x.Visible != null)).ToList(); Mapper.CreateMap<vTaxiService, TaxiServiceModel>(); return Mapper.Map<IEnumerable<TaxiServiceModel>>(views); } } catch (Exception) { throw; } }
internal static ICollection<TourChargeModel> GetTourCharges(int tourId) { try { using (SriLankaToursEntities context = new SriLankaToursEntities()) { IEnumerable<vTourCharge> tourCharges = context.vTourCharges.Where(x => x.TourId == tourId); Mapper.CreateMap<vTourCharge, TourChargeModel>(); return Mapper.Map<ICollection<TourChargeModel>>(tourCharges); } } catch (Exception) { throw; } }
internal static TaxiServiceModel UpdateTaxiService(TaxiServiceEntity service) { try { using (SriLankaToursEntities context = new SriLankaToursEntities()) { bool isServiceExists = context.TaxiServiceEntities.Any(x => (x.FromId == service.FromId) && (x.ToId == service.ToId) && (x.VehicleId == service.VehicleId) && (x.ServiceId != service.ServiceId)); if (isServiceExists) throw new TaxiServiceExistsException("Taxi service already exists"); TaxiServiceEntity entity = context.TaxiServiceEntities.Find(service.ServiceId); entity.Price = service.Price; entity.Visible = service.Visible; entity.FromId = service.FromId; entity.ToId = service.ToId; entity.UpdatedBy = service.UpdatedBy; entity.UpdatedOn = service.UpdatedOn; context.SaveChanges(); return GetTaxiService(entity.ServiceId); } } catch (Exception) { throw; } }
internal static IEnumerable<TourModel> GetToursByTourDays(bool includeInvisible, byte? noOfTourDays) { IEnumerable<vTour> view; using (SriLankaToursEntities context = new SriLankaToursEntities()) { view = (from t in context.vTours where (includeInvisible == false ? t.Visible == true : t.Visible != null) && (noOfTourDays.HasValue ? t.NoOfDays == noOfTourDays : t.NoOfDays != null) orderby t.TourId select t).ToList(); //view = context.vTours.Where(x => (includeInvisible == false ? x.Visible == false : x.Visible != null)); Mapper.CreateMap<vTour, TourModel>(); IEnumerable<TourModel> tours = Mapper.Map<IEnumerable<TourModel>>(view); return tours; } }
internal static IEnumerable<FromPlaceEntity> GetFromPlaces(bool includeHidden) { using (SriLankaToursEntities context = new SriLankaToursEntities()) { return context.FromPlaceEntities .Where(x => includeHidden == false ? x.Visible == true : x.Visible != null).ToList(); } }
internal static IEnumerable<TourDayModel> GetTourDays(int tourId) { try { using (SriLankaToursEntities context = new SriLankaToursEntities()) { IEnumerable<vTourDay> view = context.vTourDays.Where(x => x.TourId == tourId); Mapper.CreateMap<vTourDay, TourDayModel>(); return Mapper.Map<IEnumerable<vTourDay>, IEnumerable<TourDayModel>>(view); } } catch (Exception) { throw; } }
internal static TourModel UpdateTour(TourModel model) { try { TourModel tourUpdated = null; using (SriLankaToursEntities context = new SriLankaToursEntities()) { TourEntity entityTour = context.TourEntities.Find(model.TourId); if (entityTour == null) throw new TourNotFoundException(); if (string.IsNullOrEmpty(model.TourBannerImage)) model.TourBannerImage = entityTour.TourBannerImage; entityTour.NoOfDays = model.NoOfDays; entityTour.TourBannerImage = model.TourBannerImage; entityTour.TourTitle = model.TourTitle; entityTour.UpdatedBy = model.UpdatedBy; entityTour.UpdatedOn = model.UpdatedOn; entityTour.Visible = model.Visible; entityTour.Description = model.Description; context.SaveChanges(); return tourUpdated = GetTour(entityTour.TourId); } } catch (Exception) { throw; } }
internal static bool UpdateTourCharges(IList<TourChargeEntity> entities) { try { bool status = false; using (SriLankaToursEntities context = new SriLankaToursEntities()) { foreach (TourChargeEntity entity in entities) { TourChargeEntity tourcharge = context.TourChargeEntities.Find(entity.TourId, entity.VehicleId); if (tourcharge == null) { // context.Entry(entity).State = System.Data.EntityState.Added; context.TourChargeEntities.Add(entity); context.SaveChanges(); } else { //context.Entry(entity).State = System.Data.EntityState.Modified; //context.entityChargeEntities.Attach(entity); tourcharge.Price = entity.Price; tourcharge.Description = entity.Description; context.SaveChanges(); } } status = true; } return status; } catch (Exception) { throw; } }
internal static TourDetailModel GetTourAndTourDays(int tourId) { try { TourDetailModel tourDetail = new TourDetailModel(); using (SriLankaToursEntities context = new SriLankaToursEntities()) { IEnumerable<vTourDay> view = context.vTourDays.Where(x => x.TourId == tourId); tourDetail.Tour = (from t in context.vTours where t.TourId == tourId select new TourModel { TourBannerImage = t.TourBannerImage, TourTitle = t.TourTitle, TourId = t.TourId, NoOfDays = t.NoOfDays, Description = t.Description }).First(); Mapper.CreateMap<vTourDay, TourDayModel>(); tourDetail.TourDays = Mapper.Map<ICollection<TourDayModel>>(view); return tourDetail; } } catch (Exception) { throw; } }
internal static TourDayModel UpdateTourDay(TourDayModel model) { try { using (SriLankaToursEntities context = new SriLankaToursEntities()) { TourDayEntity entity = context.TourDayEntities.Find(model.TourId, model.Day); if (entity == null) throw new TourDayNotFoundException(); bool foundDuplicates = (from d in context.TourDayEntities where d.TourId == model.TourId && d.Day == model.Day && d.TourDayId != model.TourDayId select d).Any(); if(foundDuplicates) throw new TourDayExistsException("Duplicate record found with same day and tour"); if (string.IsNullOrEmpty(model.TourDayImage)) model.TourDayImage = entity.TourDayImage; entity.Title = model.Title; entity.TourDayImage = model.TourDayImage; entity.Description = model.Description; context.SaveChanges(); return GetTourDay(entity.TourDayId); } } catch (Exception) { throw; } }