public List<BlogDTO> ReadAllBlogs() { List<BlogDTO> blogList = new List<BlogDTO>(); try { if (1 > 0) { using (var tmcDBContext = new TMCContext()) { var blogs = (from blog in tmcDBContext.Blogs select blog).ToList(); foreach (var blog in blogs) { var blogDTO = new BlogDTO(); blogDTO.BlogId = blog.Id; blogDTO.Description = blog.Description; blogList.Add(blogDTO); } } } } catch (Exception ex) { //ExceptionManager.HandleException(ex); //throw new DACException("Error while fetching the organization locations.", ex); } return blogList; }
/// <summary> /// The get categories. /// </summary> /// <returns> /// Fetch list of categories <see cref=""/>. /// </returns> public IList<ICategoryDTO> ReadCategories() { IList<ICategoryDTO> categories = new List<ICategoryDTO>(); try { using (var tmcContext = new TMCContext()) { var categoryEntities = (from category in tmcContext.Category select category).ToList(); ICategoryDTO categoryDto = null; foreach (var categoryEntity in categoryEntities) { categoryDto = (ICategoryDTO)DTOFactory.Instance.Create(DTOType.Category); categoryDto.CategoryId = categoryEntity.CategoryId; categoryDto.Name = categoryEntity.Name; categoryDto.ShortName = categoryEntity.ShortName; categoryDto.Description = categoryEntity.Description; categoryDto.Popularity = categoryEntity.Popularity; categories.Add(categoryDto); } } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException("Error while fetching the categories.", ex); } return categories; }
/// <summary> /// The read cities. /// </summary> /// <returns> /// Fetch all cities <see cref="IList"/>. /// </returns> public IList<ICityDTO> ReadCities() { IList<ICityDTO> cities = new List<ICityDTO>(); try { using (var tmcContext = new TMCContext()) { var cityEntities = (from city in tmcContext.City select city).ToList(); ICityDTO cityDto = null; foreach (var cityEntity in cityEntities) { cityDto = (ICityDTO)DTOFactory.Instance.Create(DTOType.City); cityDto.CityId = cityEntity.CityId; cityDto.Name = cityEntity.Name; cityDto.StateId = cityEntity.StateId; cityDto.Lat = cityEntity.Lat; cityDto.Long = cityEntity.Long; cityDto.Radius = GlobalUtility.GetCityRadius(cityEntity.PopulationClass); cities.Add(cityDto); } } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException("Error while fetching the cities.", ex); } return cities; }
/// <summary> /// Create Help /// </summary> /// <returns> long</returns> public long CreateProduct(ProductDTO productDto) { long helpMasterID = int.MinValue; using (var tmcDBContext = new TMCContext()) { var productItem = (from product in tmcDBContext.Products where product.ProductId == 1 && product.IsActive == true select product).SingleOrDefault(); productItem.Content = productDto.Content; productItem.ContentText = productDto.ContentText; //productItem.IsActive = false; tmcDBContext.Products.AddOrUpdate(productItem); tmcDBContext.SaveChanges(); } /* try { using (IDatabase db = DatabaseFactory.CreateDatabase()) { db.Connect(); db.BeginTransaction(); db.CreateDBCommand(DatabaseConstants.Procedures.prc_ins_tbl_HelpMaster, System.Data.CommandType.StoredProcedure); db.AddParameter("HELPMASTERID", DbType.Int64, (object)help.HelpMasterID, ParameterDirection.InputOutput); db.AddParameter("PRODUCTID", DbType.Int32, HelpDAC.ValidateDataObject(help.ProductID)); db.AddParameter("SITEID", DbType.Int32, HelpDAC.ValidateDataObject(help.SiteID)); db.AddParameter("ISFOLDER", DbType.Boolean, HelpDAC.ValidateDataObject(help.IsFolder)); db.AddParameter("PARENTCODE", DbType.String, HelpDAC.ValidateDataObject(help.ParentCode)); db.AddParameter("TITLE", DbType.String, HelpDAC.ValidateDataObject(help.Title)); db.AddParameter("CONTENT", DbType.String, HelpDAC.ValidateDataObject(help.Content)); db.AddParameter("CONTENTTEXT", DbType.String, HelpDAC.ValidateDataObject(help.ContentText)); db.AddParameter("HELPCODE", DbType.String, HelpDAC.ValidateDataObject(help.HelpCode)); db.AddParameter("LANGUAGEID", DbType.Int32, HelpDAC.ValidateDataObject(help.LanguageID)); db.AddParameter("CREATEDBY", DbType.Int64, HelpDAC.ValidateDataObject(help.CreatedBy)); db.ExecuteNonQuery(); helpMasterID = db.GetOutputParameterValue<long>("HELPMASTERID"); if (helpMasterID > 0) { db.Commit(); } else { db.Rollback(); } } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException("An exception Saving Help", ex); }*/ return 1; }
/// <summary> /// /// </summary> /// <param name="paymentModes"></param> /// <returns></returns> public int AddUpdateListingPaymentModes(IListingPaymentModesDTO paymentModes) { int retVal = 0; try { if (paymentModes != null) { using (TransactionScope trans = new TransactionScope()) { using (var TMCDbContext = new TMCContext()) { foreach (var paymentModeDto in paymentModes.PaymentModes) { long listingPaymentModeId = paymentModeDto.ListingPaymentModeId; if (paymentModeDto.ListingPaymentModeId > 0) { var listingPaymentModeEntity = TMCDbContext.ListingPaymentMode.SingleOrDefault( pmode => pmode.ListingPaymentModeId == listingPaymentModeId); if (listingPaymentModeEntity != null) { TMCDbContext.ListingPaymentMode.DeleteObject(listingPaymentModeEntity); } } else { var listingPaymentMode = new ListingPaymentMode(); EntityConverter.FillEntityFromDTO(paymentModeDto, listingPaymentMode); TMCDbContext.ListingPaymentMode.AddObject(listingPaymentMode); } } if (TMCDbContext.SaveChanges() > 0) { retVal = 1; } } trans.Complete(); } } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException("Error while updating listing payment modes.", ex); } return retVal; }
/// <summary> /// /// </summary> /// <param name="userDto"></param> /// <returns></returns> public long CreateUser(IUserDTO userDto) { var retVal = -1L;//public const int DefaultCreateId = -1; todo add this to Global constants try { if (userDto != null) { using (TransactionScope trans = new TransactionScope()) { using (var TMCDbContext = new TMCContext()) { var user = new User(); EntityConverter.FillEntityFromDTO(userDto, user); user.CreatedOn = DateTime.Now; user.CreatedBy = 11;//todo user.UpdatedOn = DateTime.Now; user.UpdatedBy = 11; user.IsActive = true; user.IsDeleted = false; user.UserTypeId = 1; user.AddressLine1 = "Default AddressLine1"; user.PinCode = 12345; TMCDbContext.User.AddObject(user); if (TMCDbContext.SaveChanges() > 0) { retVal = user.UserId; //userDto.ListingId = listing.ListingId; } } trans.Complete(); } } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException("Error while creating the user.", ex); } return retVal; }
public long CreateListingServiceLocation(IServiceLocationDTO serviceLocationDto) { long retVal = GlobalConstants.DefaultCreateId; try { if (serviceLocationDto != null) { using (TransactionScope trans = new TransactionScope()) { using (var TMCDbContext = new TMCContext()) { var listingServiceLocation = new ListingServiceLocation(); listingServiceLocation.ListingId = serviceLocationDto.ListingId; listingServiceLocation.CityId = serviceLocationDto.CityId; TMCDbContext.ListingServiceLocation.AddObject(listingServiceLocation); //todo fill these calues listingServiceLocation.StateId = 1; listingServiceLocation.CountryId = 1; listingServiceLocation.IsCityLevel = true; listingServiceLocation.CreatedOn = DateTime.Now; listingServiceLocation.CreatedBy = 11; listingServiceLocation.UpdatedOn = DateTime.Now; listingServiceLocation.UpdatedBy = 11; listingServiceLocation.IsActive = true; listingServiceLocation.IsDeleted = false; if (TMCDbContext.SaveChanges() > 0) { retVal = listingServiceLocation.ListingServiceLocationId; } } trans.Complete(); } } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException("Error while creating the listing detail.", ex);//todo } return retVal; }
public List<ProductDTO> ReadAllProducts() { List<ProductDTO> productList = new List<ProductDTO>(); try { if (1 > 0) { using (var tmcDBContext = new TMCContext()) { var products = (from blog in tmcDBContext.Products select blog).ToList(); foreach (var product in products) { var productDTO = new ProductDTO(); productDTO.ProductId = product.ProductId; productDTO.Description = product.Description; productDTO.Name = product.Name; productDTO.SeoTitle = product.SeoTitle; productDTO.ImageURL = product.ImageURL; productList.Add(productDTO); } } } } catch (Exception ex) { //ExceptionManager.HandleException(ex); //throw new DACException("Error while fetching the organization locations.", ex); } return productList; }
public string DeleteListingMedia(long listingMediaid) { string retVal = ""; try { using (TransactionScope trans = new TransactionScope()) { using (TMCContext tmcContext = new TMCContext()) { ListingMedia listingMediaEntity = tmcContext.ListingMedia.SingleOrDefault(lm => lm.ListingMediaId == listingMediaid); //todo check File fileEntity = tmcContext.File.SingleOrDefault(f => f.FileId == listingMediaEntity.FileId); if (listingMediaEntity != null) { tmcContext.DeleteObject(listingMediaEntity); tmcContext.DeleteObject(fileEntity); tmcContext.SaveChanges(); retVal = fileEntity.ServerFileName;//todo check for null } } trans.Complete(); } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException("Error while deleting listing media.", ex); } return retVal; }
public ProductDTO ReadProductBySeoTitle(string seoTitle) { var productDTO = new ProductDTO(); try { if (1 > 0) { using (var tmcDBContext = new TMCContext()) { var product = (from blog in tmcDBContext.Products where blog.SeoTitle == seoTitle && blog.IsActive == true select blog).SingleOrDefault(); productDTO.ProductId = product.ProductId; productDTO.Description = product.Description; productDTO.Name = product.Name; productDTO.Content = product.Content; productDTO.SeoTitle = product.SeoTitle; productDTO.ImageURL = product.ImageURL; } } } catch (Exception ex) { //ExceptionManager.HandleException(ex); //throw new DACException("Error while fetching the organization locations.", ex); } return productDTO; }
/// <summary> /// /// </summary> /// <param name="listingDto"></param> /// <returns></returns> public IListingDTO UpdateListing(IListingDTO listingDto) { try { if (listingDto != null) { using (var TMCDbContext = new TMCContext()) { var listingEntity = (from listing in TMCDbContext.Listing where listing.ListingId == listingDto.ListingId select listing).Single(); if (listingEntity != null) { EntityConverter.FillEntityFromDTO(listingDto, listingEntity); listingEntity.UpdatedOn = DateTime.Now; listingEntity.CreatedOn = DateTime.Now; } if (TMCDbContext.SaveChanges() > 0) { listingDto.ListingId = listingEntity.ListingId; } } } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException("Error while updating the listing detail.", ex); } return listingDto; }
/// <summary> /// /// </summary> /// <param name="listingDto"></param> /// <returns></returns> public IListingDTO CreateListing(IListingDTO listingDto) { try { if (listingDto != null) { using (TransactionScope trans = new TransactionScope()) { using (var TMCDbContext = new TMCContext()) { var listing = new Listing(); EntityConverter.FillEntityFromDTO(listingDto, listing); listing.CreatedOn = DateTime.Now; listing.CreatedBy = 11; listing.UpdatedOn = DateTime.Now; listing.UpdatedBy = 11; listing.IsActive = true; listing.IsDeleted = false; listing.Address = "Default Address"; listing.PinCode = 12345; listing.UserId = 3; listing.CityId = 111; TMCDbContext.Listing.AddObject(listing); if (TMCDbContext.SaveChanges() > 0) { listingDto.ListingId = listing.ListingId; } } trans.Complete(); } } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException("Error while creating the listing detail.", ex); } return listingDto; }
public IListingDTO GetServiceLocationsByListingId(int listingId) { IListingDTO listingDto = (IListingDTO)DTOFactory.Instance.Create(DTOType.Listing); IListingServiceLocationsDTO listingServiceLocationsDto = (IListingServiceLocationsDTO)DTOFactory.Instance.Create(DTOType.ListingServiceLocations); listingServiceLocationsDto.ServiceLocations = new List<IServiceLocationDTO>(); try { using (var tmcContext = new TMCContext()) { var listingServiceLocationEntities = (from listingServiceLocation in tmcContext.ListingServiceLocation join city in tmcContext.City on listingServiceLocation.CityId equals city.CityId where listingServiceLocation.ListingId == listingId && listingServiceLocation.IsActive select new { listingServiceLocation, CityName = city.Name, }).ToList(); if (listingServiceLocationEntities.Any()) { foreach (var listingServiceLocationEntity in listingServiceLocationEntities) { IServiceLocationDTO serviceLocationDto = (IServiceLocationDTO)DTOFactory.Instance.Create(DTOType.ServiceLocation); EntityConverter.FillDTOFromEntity(listingServiceLocationEntity.listingServiceLocation, serviceLocationDto); serviceLocationDto.CityName = listingServiceLocationEntity.CityName; listingServiceLocationsDto.ServiceLocations.Add(serviceLocationDto); } listingDto.ListingServiceLocations = listingServiceLocationsDto; } } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException("Error while fetching the listing contacts.", ex);//todo } return listingDto; }
public bool DeleteListingServiceLocation(long listingServiceLocationId) { bool retVal = false; try { using (TransactionScope trans = new TransactionScope()) { using (TMCContext tmcContext = new TMCContext()) { ListingServiceLocation listingServiceLocationEntity = tmcContext.ListingServiceLocation.SingleOrDefault(lcid => lcid.ListingServiceLocationId == listingServiceLocationId); if (listingServiceLocationEntity != null) { tmcContext.DeleteObject(listingServiceLocationEntity); tmcContext.SaveChanges(); } } trans.Complete(); } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException("Error while deleting listing ServiceLocation.", ex); } return retVal; }
public long CreateListingCategory(ICategoryDTO categoryDto) { long retVal = GlobalConstants.DefaultCreateId; try { if (categoryDto != null) { using (TransactionScope trans = new TransactionScope()) { using (var TMCDbContext = new TMCContext()) { var listingCategory = new ListingCategory(); listingCategory.ListingId = categoryDto.ListingId; listingCategory.CategoryId = categoryDto.CategoryId; //todo check if already added and for service location also TMCDbContext.ListingCategory.AddObject(listingCategory); if (TMCDbContext.SaveChanges() > 0) { retVal = listingCategory.ListingCategoryId; } } trans.Complete(); } } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException("Error while creating the listing detail.", ex); } return retVal; }
public IListingDTO GetPaymentModesByListingId(int listingId) { IListingDTO listingDto = (IListingDTO)DTOFactory.Instance.Create(DTOType.Listing); IListingPaymentModesDTO listingPaymentModesDto = (IListingPaymentModesDTO)DTOFactory.Instance.Create(DTOType.ListingPaymentModes); listingPaymentModesDto.PaymentModes = new List<IPaymentModeDTO>(); try { using (var tmcContext = new TMCContext()) { var listingpaymentModeEntities = (from paymentMode in tmcContext.ListingPaymentMode where paymentMode.ListingId == listingId select paymentMode).ToList(); if (listingpaymentModeEntities.Any()) { foreach (var paymentModeEntity in listingpaymentModeEntities) { IPaymentModeDTO paymentModeDto = (IPaymentModeDTO)DTOFactory.Instance.Create(DTOType.PaymentMode); EntityConverter.FillDTOFromEntity(paymentModeEntity, paymentModeDto); listingPaymentModesDto.PaymentModes.Add(paymentModeDto); } listingDto.ListingPaymentModes = listingPaymentModesDto; } } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException("Error while fetching the listing payment modes.", ex); } return listingDto; }
public IList<IListingDTO> GetListingsByUserId(int userId) { IList<IListingDTO> listings = new List<IListingDTO>(); try { using (var tmcContext = new TMCContext()) { var listingEntities = (from listing in tmcContext.Listing where listing.UserId == userId select listing).ToList(); IListingDTO listingDto = null; foreach (var listingEntity in listingEntities) { listingDto = (IListingDTO)DTOFactory.Instance.Create(DTOType.Listing);//todo listingDto.ListingId = listingEntity.ListingId; listingDto.BusinessName = listingEntity.BusinessName; listingDto.Website = listingEntity.Website; listings.Add(listingDto); } } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException("Error while fetching the listings.", ex); } return listings; }
public IListingDTO GetListingById(int listingId) { IListingDTO listingDto = null; try { using (var tmcContext = new TMCContext()) { var listingEntity = (from listing in tmcContext.Listing where listing.ListingId == listingId && listing.IsActive select listing).Single(); listingDto = (IListingDTO)DTOFactory.Instance.Create(DTOType.Listing); listingDto.ListingId = listingEntity.ListingId; listingDto.BusinessName = listingEntity.BusinessName; listingDto.BusinessDays = listingEntity.BusinessDays; listingDto.BusinessHours = listingEntity.BusinessHours; listingDto.ContactPerson = listingEntity.ContactPerson; listingDto.ContactEmailId = listingEntity.ContactEmailId; listingDto.Designation = listingEntity.Designation; listingDto.Website = listingEntity.Website; listingDto.YearStarted = listingEntity.YearStarted; } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException("Error while fetching the listing detail.", ex); } return listingDto; }
public IListingDTO GetContactsByListingId(int listingId) { IListingDTO listingDto = (IListingDTO)DTOFactory.Instance.Create(DTOType.Listing); IListingContactsDTO listingContactsDto = (IListingContactsDTO)DTOFactory.Instance.Create(DTOType.ListingContacts); listingContactsDto.Contacts = new List<IContactDTO>(); try { using (var tmcContext = new TMCContext()) { var listingcontactEntities = (from listingContact in tmcContext.ListingContact where listingContact.ListingId == listingId && listingContact.IsActive select listingContact).ToList(); if (listingcontactEntities.Any()) { foreach (var listingContactEntity in listingcontactEntities) { IContactDTO listingContactDto = (IContactDTO)DTOFactory.Instance.Create(DTOType.Contact); EntityConverter.FillDTOFromEntity(listingContactEntity, listingContactDto); listingContactsDto.Contacts.Add(listingContactDto); } listingDto.ListingContacts = listingContactsDto; } } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException("Error while fetching the listing contacts.", ex); } return listingDto; }
public IMediaDTO CreateListingMedia(IFileDTO fileDto) { IMediaDTO mediaDto = (IMediaDTO)DTOFactory.Instance.Create(DTOType.Media); try { if (fileDto != null) { using (TransactionScope trans = new TransactionScope()) { using (var TMCDbContext = new TMCContext()) { var fileEntity = new File(); //EntityConverter.FillEntityFromDTO(fileDto, fileEntity); fileEntity.CreatedOn = DateTime.Now; fileEntity.CreatedBy = 11; fileEntity.UpdatedOn = DateTime.Now; fileEntity.UpdatedBy = 11; fileEntity.IsActive = true; fileEntity.IsDeleted = false; fileEntity.FileTitle = fileDto.FileTitle; fileEntity.OriginalFileName = fileDto.OriginalFileName; fileEntity.ServerFileName = fileDto.ServerFileName; fileEntity.ServerPath = fileDto.ServerPath; fileEntity.FileExtensionId = fileDto.FileExtensionId; fileEntity.FileTypeId = fileDto.FileTypeId; TMCDbContext.File.AddObject(fileEntity); if (TMCDbContext.SaveChanges() > 0) { fileDto.FileId = fileEntity.FileId; var listingMediaEntity = new ListingMedia(); //EntityConverter.FillEntityFromDTO(fileDto, fileEntity);//todo do later listingMediaEntity.CreatedOn = DateTime.Now; listingMediaEntity.CreatedBy = 11; listingMediaEntity.UpdatedOn = DateTime.Now; listingMediaEntity.UpdatedBy = 11; listingMediaEntity.IsActive = true; listingMediaEntity.IsDeleted = false; listingMediaEntity.ListingId = fileDto.ListingId; listingMediaEntity.FileId = fileDto.FileId; TMCDbContext.ListingMedia.AddObject(listingMediaEntity); if (TMCDbContext.SaveChanges() > 0) { mediaDto.ListingMediaId = listingMediaEntity.ListingMediaId; mediaDto.FileId = listingMediaEntity.FileId; mediaDto.FileName = fileDto.OriginalFileName; mediaDto.ServerFileName = fileDto.ServerFileName; } } } trans.Complete(); } } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException("Error while creating the listing detail.", ex); } return mediaDto; }
/// <summary> /// The read listings. /// </summary> /// <param name="cityId"> /// The city id. /// </param> /// <param name="placeId"> /// The place id. /// </param> /// <param name="categoryId"> /// The category id. /// </param> /// <returns> /// The <see cref="IList"/>. /// </returns> public IList<IListingDTO> ReadListings(int cityId, string placeId, int categoryId) { IList<IListingDTO> listings = new List<IListingDTO>(); try { using (var tmcContext = new TMCContext()) { var listingEntities = (from listing in tmcContext.Listing //join loc in tmcContext.ListingLocation on listing.ListingId equals loc.ListingId //join area in tmcContext.Area on loc.AreaId equals area.AreaId //where loc.CityId == cityId //&& area.CityId == cityId //&& (placeId == null || area.PlaceId == placeId) select listing).ToList(); IListingDTO listingDto = null; foreach (var listingEntity in listingEntities) { listingDto = (IListingDTO)DTOFactory.Instance.Create(DTOType.Listing); listingDto.ListingId = listingEntity.ListingId; listingDto.BusinessName = listingEntity.BusinessName; listingDto.BusinessDays = listingEntity.BusinessDays; listingDto.BusinessHours = listingEntity.BusinessHours; listingDto.ContactPerson = listingEntity.ContactPerson; listingDto.ContactEmailId = listingEntity.ContactEmailId; listingDto.Designation = listingEntity.Designation; listingDto.Website = listingEntity.Website; listingDto.YearStarted = listingEntity.YearStarted; listings.Add(listingDto); } } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException("Error while fetching the listings.", ex); } return listings; }
public IListingDTO GetMediasByListingId(int listingId) { IListingDTO listingDto = (IListingDTO)DTOFactory.Instance.Create(DTOType.Listing); IListingMediasDTO listingMediasDto = (IListingMediasDTO)DTOFactory.Instance.Create(DTOType.ListingMedias); listingMediasDto.Medias = new List<IMediaDTO>(); try { using (var tmcContext = new TMCContext()) { var listingMediaEntities = (from listingMedia in tmcContext.ListingMedia join file in tmcContext.File on listingMedia.FileId equals file.FileId where listingMedia.ListingId == listingId && listingMedia.IsActive select new { listingMedia, FileName = file.OriginalFileName, ServerFileName = file.ServerFileName }).ToList(); if (listingMediaEntities.Any()) { foreach (var listingMediaEntity in listingMediaEntities) { IMediaDTO listingMediaDto = (IMediaDTO)DTOFactory.Instance.Create(DTOType.Media); EntityConverter.FillDTOFromEntity(listingMediaEntity.listingMedia, listingMediaDto); listingMediaDto.FileName = listingMediaEntity.FileName; listingMediaDto.ServerFileName = listingMediaEntity.ServerFileName; listingMediasDto.Medias.Add(listingMediaDto); } listingDto.ListingMedias = listingMediasDto; } } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException("Error while fetching the listing medias.", ex); } return listingDto; }
public IListingDTO GetCategoriesByListingId(int listingId) { IListingDTO listingDto = (IListingDTO)DTOFactory.Instance.Create(DTOType.Listing); IListingCategoriesDTO listingCategoriesDto = (IListingCategoriesDTO)DTOFactory.Instance.Create(DTOType.ListingCategories); listingCategoriesDto.Categories = new List<ICategoryDTO>(); try { using (var tmcContext = new TMCContext()) { var listingcategoriesEntities = (from listingCategory in tmcContext.ListingCategory join category in tmcContext.Category on listingCategory.CategoryId equals category.CategoryId where listingCategory.ListingId == listingId select new { category, ListingCategoryId = listingCategory.ListingCategoryId, ListingId = listingCategory.ListingId }).ToList(); if (listingcategoriesEntities.Any()) { foreach (var listingCategoryEntity in listingcategoriesEntities) { ICategoryDTO categoryDto = (ICategoryDTO)DTOFactory.Instance.Create(DTOType.Category); EntityConverter.FillDTOFromEntity(listingCategoryEntity.category, categoryDto); categoryDto.ListingId = listingCategoryEntity.ListingId; categoryDto.ListingCategoryId = listingCategoryEntity.ListingCategoryId; listingCategoriesDto.Categories.Add(categoryDto); } listingDto.ListingCategories = listingCategoriesDto; } } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException("Error while fetching the listing contacts.", ex); } return listingDto; }