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