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; } }
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; } }
/// <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 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 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 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 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; } }
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 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; } }