private IProductDTO getProductDTO(ProductItemViewModel productMaster, bool creatingProduct)
        {
            IProductDTO product = (IProductDTO)DTOFactory.Instance.Create(DTOType.Product);

            try
            {
                product.ProductId   = 1;
                product.Name        = "Pay TTm";// productMaster.Title.Trim();
                product.Content     = productMaster.Content.Trim();
                product.ContentText = productMaster.ContentText;
                if (creatingProduct)
                {
                    //product.CreatedBy = this.LoggedInUserID;
                }

                /*   else
                 * {
                 *     help.ModifiedBy = this.LoggedInUserID;
                 *     if (!string.IsNullOrEmpty(helpMaster.HelpCode))
                 *        help.HelpCode = helpMaster.HelpCode.Trim();
                 * } */
            }
            catch (Exception ex)
            {
                //ExceptionManager.HandleException(ex);
            }
            return(product);//
        }
Example #2
0
        /// <summary>
        /// Edit product from database
        /// </summary>
        /// <param name="productDTO"></param>
        /// <returns></returns>
        public int EditProduct(IProductDTO productDTO)
        {
            var config = new MapperConfiguration(cfg => cfg.CreateMap <IProductDTO, IProduct>());
            var mapper = config.CreateMapper();

            productDTO = CheckAndUpdateImage(productDTO);
            return(_productDataAccess.EditProduct(mapper.Map <IProduct>(productDTO)));
        }
Example #3
0
        /// <summary>
        /// add a product to database
        /// </summary>
        /// <param name="productDTO"></param>
        /// <returns></returns>
        public int AddProduct(IProductDTO productDTO)
        {
            var config = new MapperConfiguration(cfg => cfg.CreateMap <ProductDTO, Product>());
            var mapper = config.CreateMapper();

            productDTO = SaveImage(productDTO);
            return(_productDataAccess.AddProduct(mapper.Map <Product>(productDTO)));
        }
Example #4
0
        /// <summary>
        /// Create Help
        /// </summary>
        /// <returns> long</returns>
        public long CreateProduct(IProductDTO 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);
        }
Example #5
0
        /// <summary>
        /// Create Help
        /// </summary>
        /// <returns> long</returns>
        public long CreateProduct(IProductDTO 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;
        }
Example #6
0
        public async void KeyProducts()
        {
            IProductDTO apple = await _ctx.Products.GetProductByIdAsync(1);

            Assert.Equal("Red Delicious Apples", apple.Name);
            Assert.Equal(5.00M, apple.Price);
            IProductDTO orange = await _ctx.Products.GetProductByIdAsync(2);

            Assert.Equal("Navel Oranges", orange.Name);
            Assert.Equal(10.00M, orange.Price);
        }
Example #7
0
        public void UploadProduct(IProductDTO product)
        {
            Product p = new Product()
            {
                ProdName        = product.ProdName,
                ProdDescription = product.ProdDescription,
                BrutPrice       = product.BrutPrice,
                VAT             = product.VAT
            };

            _ctx.Products.Add(p);
            _ctx.SaveChanges();
        }
Example #8
0
        public void ModifyProduct(IProductDTO Product, int prodId)
        {
            var oprod = _ctx.Products.First(x => x.ProdId == Product.ProdId);

            oprod.ProdName        = Product.ProdName;
            oprod.ProdDescription = Product.ProdDescription;
            oprod.IsActiveProd    = Product.IsActiveProd;
            if (oprod.BrutPrice != Product.BrutPrice)
            {
                oprod.ProdPriceChanged = DateTime.UtcNow.Date;
                oprod.BrutPrice        = Product.BrutPrice;
            }
            oprod.VAT = Product.VAT;
            _ctx.SaveChanges();
        }
        private Product MapProduct(IProductDTO product)
        {
            var productToReturn = new Product
                                      {
                                          ASIN = product.ASIN,
                                          Authors = product.Authors(),
                                          AuthorsMLA = product.AuthorsInMlaFormat(),
                                          ImageUrl = product.ProductImageUrl(amazonRequest.AssociateTag),
                                          ProductPreviewUrl = product.ProductPreviewUrl(amazonRequest.AssociateTag),
                                          Publisher = product.Publisher,
                                          Title = product.Title,
                                          Url = product.Url
                                      };

            return productToReturn;
        }
Example #10
0
        /// <summary>
        /// Saves product image to folder.
        /// </summary>
        /// <param name="productDTO"></param>
        /// <returns></returns>
        private IProductDTO SaveImage(IProductDTO productDTO)
        {
            if (productDTO.Image != null)
            {
                using (var ms = new MemoryStream())
                {
                    productDTO.Image.CopyTo(ms);
                    productDTO.Product_Image = ms.ToArray();
                }
            }
            if (productDTO.Image != null)
            {
                productDTO.Product_Image_Name = $"{productDTO.Product_name}_pic.png";
            }

            return(productDTO);
        }
Example #11
0
 /// <summary>
 /// Check if new image is present in dto it will update image in database
 /// </summary>
 /// <param name="productDTO"></param>
 /// <returns></returns>
 private IProductDTO CheckAndUpdateImage(IProductDTO productDTO)
 {
     if (productDTO.Image == null)
     {
         var oldProduct = GetProductById(productDTO.Product_id);
         if (oldProduct != null)
         {
             productDTO.Product_Image      = oldProduct.Product_Image;
             productDTO.Product_Image_Name = oldProduct.Product_Image_Name;
         }
     }
     else
     {
         productDTO = SaveImage(productDTO);
     }
     return(productDTO);
 }
        private Review MapProductAndReview(IProductDTO product, IReviewDTO review)
        {
            var reviewToReturn = new Review
                                     {
                                         ASIN = product.ASIN,
                                         Authors = product.Authors(),
                                         AuthorsMLA = product.AuthorsInMlaFormat(),
                                         ImageUrl = product.ProductImageUrl(amazonRequest.AssociateTag),
                                         ProductPreviewUrl = product.ProductPreviewUrl(amazonRequest.AssociateTag),
                                         Publisher = product.Publisher,
                                         Title = product.Title,
                                         Url = product.Url,
                                         Content = review.Content,
                                         Date = review.Date,
                                         HelpfulVotes = review.HelpfulVotes,
                                         Rating = review.Rating,
                                         Summary = review.Summary,
                                         TotalVotes = review.TotalVotes
                                     };

            return reviewToReturn;
        }
        }                     // hide the constructor

        public Product(IProductDTO dto)
        {
            _dto = dto;
        }
        public JsonResult CreateHelp(ProductItemViewModel productMaster)
        {
            //OperationResult<long> createHelpResult = null;
            ActionResult actionResult = null;
            IProductDTO  helpDTO      = this.getProductDTO(productMaster, true);

            // helpDTO.ModifiedBy = this.LoggedInUserID;

            //HelpVersionWorkFlowStep workflowStep=(HelpVersionWorkFlowStep)Enum.Parse(typeof(HelpVersionWorkFlowStep), helpMaster.VersionWorkflowStep);
            //helpDTO.VersionWorkflowStep = workflowStep == HelpVersionWorkFlowStep.CHECKINANDAPPROVE ? HelpVersionWorkflowStatus.PENDINGFORAPPROVALBYCLIENTADMIN : HelpVersionWorkflowStatus.PENDINGFORAPPROVALBYSITEADMIN;

            ProductDAC producManager = new ProductDAC();
            var        result        = producManager.CreateProduct(helpDTO);

            /*if (createHelpResult != null && createHelpResult.IsValid())
             * {
             *  ProductSettings productSettings = new ProductSettings(this.ProductID, this.LoggedInSiteID, this.LanguageID, true);
             *  helpResult = helpManager.GetHelpInformation(createHelpResult.Data, productSettings, this.LoggedInUserID, HelpVersion.Default);
             *  if (helpResult != null && helpResult.IsValid())
             *  {
             *      helpDTO = helpResult.Data;
             *      HelpTreeNode helpNode = new HelpTreeNode();
             *      if (helpDTO.Title.Length > 20)
             *      {
             *          helpNode.title = helpDTO.Title.Substring(0, 18) + "..";
             *      }
             *      else
             *      {
             *          helpNode.title = helpDTO.Title;
             *      }
             *      helpNode.tooltip = helpDTO.Title;
             *      helpNode.isFolder = helpDTO.IsFolder;
             *      helpNode.key = helpDTO.HelpMasterID.ToString();
             *
             *      helpNode.prevKey = prevHelpMasterID.ToString();
             *      helpNode.absolutePath = helpDTO.HelpAbsolutePath;
             *
             *      helpNode.canEdit = helpDTO.CreatedBy == this.LoggedInUserID ||
             *                             this.UserRole == UserRole.Administrator ||
             *                             this.UserRole == UserRole.SuperClientAdministrator;
             *
             *      helpDTO = GetUserDetails(helpDTO);
             *
             *      createHelpModel.HelpMasterId = helpDTO.HelpMasterID;
             *      createHelpModel.JsonHelpTreeNode = JsonUtility.Serialize(helpNode);
             *
             *
             *
             *      finalOperationResult = OperationResult<CreateHelpModel>.CreateSuccessResult(createHelpModel);
             *      actionResult = SmartView<CreateHelpModel>(finalOperationResult);
             *  }
             *  else
             *  {
             *      finalOperationResult = OperationResult<CreateHelpModel>.CreateFailureResult("Error while getting help information.");
             *      actionResult = SmartView<CreateHelpModel>(finalOperationResult);
             *  }*/

            //}

            /*   else
             * {
             *     finalOperationResult = OperationResult<CreateHelpModel>.CreateFailureResult("Help could not be created");
             *     actionResult = SmartView<CreateHelpModel>(finalOperationResult);
             * }*/

            return(Json(true));// actionResult;
        }