public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] ProductCategoryType productCategoryType)
        {
            if (id != productCategoryType.Id)
            {
                return(Json("404"));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    productCategoryType.UpdatedAt = DateTime.Now;
                    _context.Update(productCategoryType);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductCategoryTypeExists(productCategoryType.Id))
                    {
                        return(Json("404"));
                    }
                    else
                    {
                        throw;
                    }
                }
                return(Json("ok"));
            }
            return(Json("no"));
        }
 public IActionResult UpdateProductCategoryType(UpdateProductCategoryTypeModel updateProductCategoryTypeModel)
 {
     try
     {
         if (ModelState.IsValid)
         {
             ProductCategoryType productCategoryTypeModel = ProductCategoryTypeHelper.BindProductCategoryModel(updateProductCategoryTypeModel);
             long productCategoryTypeId = iProductCategoryType.UpdateProductCategoryType(productCategoryTypeModel, DBHelper.ParseInt64(productCategoryTypeModel.UpdatedBy));
             if (productCategoryTypeId > 0)
             {
                 return(Ok(ResponseHelper.Success(MessageConstants.ProductCategoryTypeUpdated)));
             }
             else if (productCategoryTypeId == ReturnCode.AlreadyExist.GetHashCode())
             {
                 return(Ok(ResponseHelper.Error(MessageConstants.TryDifferentName)));
             }
             else
             {
                 return(Ok(ResponseHelper.Error(MessageConstants.ProductCategoryTypeNotUpdated)));
             }
         }
         else
         {
             return(Ok(ResponseHelper.Error(MessageConstants.CompulsoryData)));
         }
     }
     catch (Exception ex)
     {
         LogHelper.ExceptionLog(ex.Message + "  :::::  " + ex.StackTrace);
         return(Ok(ResponseHelper.Error(ex.Message)));
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the mock product category.
        /// </summary>
        /// <param name="typeCategory">The type category.</param>
        /// <returns></returns>
        public ProductCategory getMockProductCategory(ProductCategoryType typeCategory)
        {
            ProductCategory productCategory = new ProductCategory();

            productCategory.Id   = (int)typeCategory;
            productCategory.Name = typeCategory.ToString("g");
            return(productCategory);
        }
Ejemplo n.º 4
0
 private void GetChildren(IList <ProductCategoryType> objList, ProductCategoryType item)
 {
     foreach (ProductCategoryType k in item.children)
     {
         List <ProductCategoryType> kList = objList.Where(p => p.ParentId == k.Id).OrderByDescending(p => p.SortCode).ToList();
         k.children = kList;
         GetChildren(objList, k);
     }
 }
Ejemplo n.º 5
0
 public IActionResult AddCampaign([FromForm] AddUpdateCampaignModel addCampaignModel)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var productCategoryTypeModel = iProductCategoryType.ProductCategoryTypeDetail(DBHelper.ParseInt64(addCampaignModel.CampaignId));
             var hostingPath = env.ContentRootPath;
             ProductCategoryType productCategoryType = ProductCategoryTypeHelper.BindProductCategoryTypeModel(addCampaignModel, hostingPath, productCategoryTypeModel);
             if (addCampaignModel.CampaignId <= 0)
             {
                 long productCategoryTypeId = iProductCategoryType.AddNewProductCategoryType(productCategoryType, addCampaignModel.ProductId);
                 if (productCategoryTypeId > 0)
                 {
                     return(Ok(ResponseHelper.Success(MessageConstants.CampaignAdded)));
                 }
                 else if (productCategoryTypeId == ReturnCode.AlreadyExist.GetHashCode())
                 {
                     ProductCategoryTypeHelper.DeleteProductImageToFolder(productCategoryType.Image, hostingPath);
                     return(Ok(ResponseHelper.Error(MessageConstants.CampaignExists)));
                 }
                 else
                 {
                     ProductCategoryTypeHelper.DeleteProductImageToFolder(productCategoryType.Image, hostingPath);
                     return(Ok(ResponseHelper.Error(MessageConstants.CampaignNotAdded)));
                 }
             }
             else
             {
                 long productCategoryTypeId = iProductCategoryType.UpdateProductCategoryType(productCategoryType, DBHelper.ParseInt64(productCategoryType.UpdatedBy), addCampaignModel.ProductId);
                 if (productCategoryTypeId > 0)
                 {
                     return(Ok(ResponseHelper.Success(MessageConstants.CampaignUpdated)));
                 }
                 else if (productCategoryTypeId == ReturnCode.AlreadyExist.GetHashCode())
                 {
                     ProductCategoryTypeHelper.DeleteProductImageToFolder(productCategoryType.Image, hostingPath);
                     return(Ok(ResponseHelper.Error(MessageConstants.CampaignExists)));
                 }
                 else
                 {
                     ProductCategoryTypeHelper.DeleteProductImageToFolder(productCategoryType.Image, hostingPath);
                     return(Ok(ResponseHelper.Error(MessageConstants.CampaignNotUpdated)));
                 }
             }
         }
         else
         {
             return(Ok(ResponseHelper.Error(MessageConstants.CompulsoryData)));
         }
     }
     catch (Exception ex)
     {
         LogHelper.ExceptionLog(ex.Message + "  :::::  " + ex.StackTrace);
         return(Ok(ResponseHelper.Error(ex.Message)));
     }
 }
        public async Task <IActionResult> Create([Bind("Id,Name")] ProductCategoryType productCategoryType)
        {
            if (ModelState.IsValid)
            {
                _context.Add(productCategoryType);
                await _context.SaveChangesAsync();

                return(Json("ok"));
            }
            return(Json("no"));
        }
Ejemplo n.º 7
0
 private void GetChildren(IList <ProductCategoryType> objList, ProductCategoryType item, List <SystemTree> trees)
 {
     foreach (ProductCategoryType k in item.children)
     {
         SystemTree tree = trees.Find(p => p.id == k.Id.ToString());
         List <ProductCategoryType> kList = objList.Where(p => p.ParentId == k.Id).OrderByDescending(p => p.SortCode).ToList();
         k.children = kList;
         List <SystemTree> mlist = ConvertToTree(kList);
         tree.children = mlist;
         GetChildren(objList, k, mlist);
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets the mock product.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <param name="name">The name.</param>
        /// <param name="price">The price.</param>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public Product getMockProduct(int id, String name, decimal price, ProductCategoryType typeCategory)
        {
            ProductCategory productCategory = getMockProductCategory(typeCategory);
            Product         p = new Product();

            p.Id                = id;
            p.Name              = name;
            p.productCategory   = productCategory;
            p.ProductCategoryId = productCategory.Id;
            p.Price             = price;
            return(p);
        }
Ejemplo n.º 9
0
 public ActionResult Edit(ProductCategoryType obj)
 {
     try
     {
         NSession.Update(obj);
         NSession.Flush();
     }
     catch (Exception ee)
     {
         return(Json(new { IsSuccess = false, ErrorMsg = "出错了" }));
     }
     return(Json(new { IsSuccess = true }));
 }
Ejemplo n.º 10
0
        /// <summary>
        /// 根据Id获取
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public ProductCategoryType GetById(int Id)
        {
            ProductCategoryType obj = NSession.Get <ProductCategoryType>(Id);

            if (obj == null)
            {
                throw new Exception("返回实体为空");
            }
            else
            {
                return(obj);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Converts the product category type list model.
        /// </summary>
        /// <param name="productCategoryTypeModel">The model.</param>
        /// <returns></returns>
        public static ProductCategoryTypeDataModel BindProductCategoryTypeListModel(ProductCategoryType productCategoryTypeModel)
        {
            ProductCategoryTypeDataModel productCategoryTypeListModel = new ProductCategoryTypeDataModel();

            if (productCategoryTypeModel != null)
            {
                productCategoryTypeListModel.Name = productCategoryTypeModel.CategoryType;
                productCategoryTypeListModel.ProductCategoryTypeId = productCategoryTypeModel.ProductCategoryTypeId;
                //productCategoryTypeListModel.ProductCategory = productCategoryTypeModel.ProductCategory.Name;
                //productCategoryTypeListModel.ProductCategoryId = productCategoryTypeModel.ProductCategoryFK;
            }
            return(productCategoryTypeListModel);
        }
Ejemplo n.º 12
0
 public JsonResult DeleteConfirmed(int id)
 {
     try
     {
         ProductCategoryType obj = GetById(id);
         NSession.Delete(obj);
         NSession.Flush();
     }
     catch (Exception ee)
     {
         return(Json(new { IsSuccess = false, ErrorMsg = "出错了" }));
     }
     return(Json(new { IsSuccess = true }));
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Converts to product category type model.
        /// </summary>
        /// <param name="addProductCategoryTypeModel">The model.</param>
        /// <returns></returns>
        public static ProductCategoryType BindProductCategoryTypeModel(AddProductCategoryTypeModel addProductCategoryTypeModel)
        {
            ProductCategoryType productCategoryTypeModel = new ProductCategoryType();

            if (addProductCategoryTypeModel != null)
            {
                productCategoryTypeModel.CategoryType = addProductCategoryTypeModel.CategoryType;
                //productCategoryTypeModel.ProductCategoryFK = addProductCategoryTypeModel.ProductCategoryId;
                productCategoryTypeModel.ProductCategoryFK = ProductCategoryEnum.Styles.GetHashCode();
                productCategoryTypeModel.CreatedBy         = addProductCategoryTypeModel.CreatedBy;
                productCategoryTypeModel.CreatedOn         = DateTime.Now;
            }
            return(productCategoryTypeModel);
        }
Ejemplo n.º 14
0
        }    //+

        //GetProductsByCategoryName parametr olarig ProductCategoryType cinsinden productCategory isdiyir
        public void GetProductsByCategoryName(ProductCategoryType productCategory)
        {
            List <Product> list = _products.FindAll(p => p.ProductCategory == productCategory).ToList();

            if (list.Count == 0)
            {
                Console.WriteLine("");
                Console.WriteLine("Bu kateqoriyada məhsul yoxdur!");
            }
            else
            {
                foreach (var item in list)
                {
                    Console.WriteLine("{0},{1},{2}", item.ProductCode, item.ProductName, item.ProductPrice);
                }
            }
        }   // +
        //
        // Summary:
        //     Kateqoriyasına görə məhsulların göstərilməsi.
        public void GetProductsByCategoryName(ProductCategoryType productCategory)
        {
            List <Product> list = _products.FindAll(p => p.ProductCategory == productCategory).ToList();

            if (list.Count == 0)
            {
                Console.WriteLine("");
                Console.WriteLine("-------------- Bu kateqoriyaya aid məhsul yoxdur! --------------");
            }
            else
            {
                foreach (var item in list)
                {
                    Console.WriteLine("----------------------------");
                    Console.WriteLine("{0},{1},{2}", "Məhsulun kodu: " + item.ProductCode, "\n" + "Məhsulun adı: " + item.ProductName, "\n" + "Məhsulun qiyməyi: " + item.ProductPrice);
                }
            }
        }
 /// <summary>
 /// Adds the new type of the product category.
 /// </summary>
 /// <param name="productCategoryType">The model.</param>
 /// <returns></returns>
 /// <exception cref="NotImplementedException"></exception>
 public long AddNewProductCategoryType(ProductCategoryType productCategoryType, string productIds = "")
 {
     try
     {
         var productCategoryTypeModel = context.ProductCategoryType.Where(x => x.CategoryType == productCategoryType.CategoryType && x.IsDelete == false).FirstOrDefault();
         if (productCategoryTypeModel == null)
         {
             context.ProductCategoryType.Add(productCategoryType);
             context.SaveChanges();
             if (!string.IsNullOrWhiteSpace(productIds))
             {
                 string[] splitProductIds = productIds.Split(',');
                 if (splitProductIds != null && splitProductIds.Length > 0)
                 {
                     foreach (var item in splitProductIds)
                     {
                         if (!string.IsNullOrWhiteSpace(item))
                         {
                             ProductCategoryDetail productCategoryDetail = new ProductCategoryDetail();
                             productCategoryDetail.ProductCategoryTypeFK = productCategoryType.ProductCategoryTypeId;
                             productCategoryDetail.ProductFK             = DBHelper.ParseInt64(item);
                             context.ProductCategoryDetail.Add(productCategoryDetail);
                             context.SaveChanges();
                         }
                     }
                 }
             }
             return(productCategoryType.ProductCategoryTypeId);
         }
         else
         {
             return(ReturnCode.AlreadyExist.GetHashCode());
         }
     }
     catch (Exception ex)
     {
         LogHelper.ExceptionLog(ex.Message + "  :::::  " + ex.StackTrace);
         throw ex;
     }
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Binds the product category type model.
        /// </summary>
        /// <param name="addProductCategoryTypeModel">The add product category type model.</param>
        /// <param name="hostPath">The host path.</param>
        /// <returns></returns>
        public static ProductCategoryType BindProductCategoryTypeModel(AddUpdateCampaignModel addProductCategoryTypeModel, string hostPath, ProductCategoryType productCategoryType)
        {
            ProductCategoryType productCategoryTypeModel = new ProductCategoryType();

            if (addProductCategoryTypeModel != null)
            {
                if (DBHelper.ParseInt64(addProductCategoryTypeModel.CampaignId) <= 0)
                {
                    productCategoryTypeModel.CreatedBy = DBHelper.ParseInt64(addProductCategoryTypeModel.UpdatedBy);
                    productCategoryTypeModel.CreatedOn = DateTime.Now;
                    productCategoryTypeModel.Image     = SaveProductCategoryTypeImageToFolder(addProductCategoryTypeModel.Image, hostPath);
                }
                else
                {
                    productCategoryTypeModel.ProductCategoryTypeId = DBHelper.ParseInt64(addProductCategoryTypeModel.CampaignId);
                    productCategoryTypeModel.UpdatedBy             = DBHelper.ParseInt64(addProductCategoryTypeModel.UpdatedBy);
                    productCategoryTypeModel.ModifiedOn            = DateTime.Now;
                    if (addProductCategoryTypeModel.IsImageDeleted)
                    {
                        DeleteProductImageToFolder(productCategoryType.Image, hostPath);
                        productCategoryTypeModel.Image = string.Empty;
                    }
                    else if (addProductCategoryTypeModel.Image == null)
                    {
                        productCategoryTypeModel.Image = productCategoryType.Image;
                    }
                    else
                    {
                        productCategoryTypeModel.Image = SaveProductCategoryTypeImageToFolder(addProductCategoryTypeModel.Image, hostPath);
                    }
                }
                productCategoryTypeModel.CategoryType      = addProductCategoryTypeModel.CampaignName;
                productCategoryTypeModel.ProductCategoryFK = ProductCategoryEnum.Campaign.GetHashCode();
                productCategoryTypeModel.Description       = addProductCategoryTypeModel.Description;
                productCategoryTypeModel.IsShowInFrontend  = addProductCategoryTypeModel.IsShowinFrontend;
            }
            return(productCategoryTypeModel);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Converts to product category model.
        /// </summary>
        /// <param name="updateProductCategoryTypeModel">The model.</param>
        /// <returns></returns>
        public static ProductCategoryType BindProductCategoryModel(UpdateProductCategoryTypeModel updateProductCategoryTypeModel, bool isUpdate = false)
        {
            ProductCategoryType productCategoryTypeModel = new ProductCategoryType();

            if (updateProductCategoryTypeModel != null)
            {
                //productCategoryTypeModel.ProductCategoryFK = updateProductCategoryTypeModel.ProductCategoryId;
                productCategoryTypeModel.ProductCategoryTypeId = updateProductCategoryTypeModel.ProductCategoryTypeId;
                productCategoryTypeModel.CategoryType          = updateProductCategoryTypeModel.CategoryType;
                productCategoryTypeModel.ProductCategoryFK     = ProductCategoryEnum.Styles.GetHashCode();
                if (isUpdate)
                {
                    productCategoryTypeModel.UpdatedBy  = updateProductCategoryTypeModel.UpdatedBy;
                    productCategoryTypeModel.ModifiedOn = DateTime.Now;
                }
                else
                {
                    productCategoryTypeModel.CreatedBy = updateProductCategoryTypeModel.UpdatedBy;
                    productCategoryTypeModel.CreatedOn = DateTime.Now;
                }
            }
            return(productCategoryTypeModel);
        }
Ejemplo n.º 19
0
 public List <Product> GetProductsByCategory(ProductCategoryType category)
 {
     return(_productRepository.GetProducts(category));
 }
Ejemplo n.º 20
0
 public List <Product> GetProducts(ProductCategoryType category)
 {
     return(_context.Products.Where(x => x.ProductType == category).ToList());
 }
Ejemplo n.º 21
0
        public ActionResult Edit(int id)
        {
            ProductCategoryType obj = GetById(id);

            return(View(obj));
        }
        /// <summary>
        /// Updates the type of the product category.
        /// </summary>
        /// <param name="productCategoryType">The model.</param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public long UpdateProductCategoryType(ProductCategoryType productCategoryType, long updatedBy, string productIds = "")
        {
            try
            {
                var productCategoryTypeModelCheck = context.ProductCategoryType.Where(x => x.CategoryType == productCategoryType.CategoryType && x.IsDelete == false && x.ProductCategoryTypeId != productCategoryType.ProductCategoryTypeId).FirstOrDefault();
                if (productCategoryTypeModelCheck == null)
                {
                    var productCategoryTypeModel = context.ProductCategoryType.Where(x => x.ProductCategoryTypeId == productCategoryType.ProductCategoryTypeId && x.IsDelete == false).FirstOrDefault();
                    if (productCategoryTypeModel != null)
                    {
                        productCategoryTypeModel.ModifiedOn        = DateTime.Now;
                        productCategoryTypeModel.UpdatedBy         = updatedBy;
                        productCategoryTypeModel.CategoryType      = productCategoryType.CategoryType;
                        productCategoryTypeModel.Image             = productCategoryType.Image;
                        productCategoryTypeModel.Description       = productCategoryType.Description;
                        productCategoryTypeModel.IsShowInFrontend  = productCategoryType.IsShowInFrontend;
                        productCategoryTypeModel.ProductCategoryFK = productCategoryType.ProductCategoryFK;
                        context.SaveChanges();

                        if (!string.IsNullOrWhiteSpace(productIds))
                        {
                            var productCategory = context.ProductCategoryDetail.Where(x => x.ProductCategoryTypeFK == productCategoryTypeModel.ProductCategoryTypeId).ToList();
                            if (productCategory != null)
                            {
                                foreach (var item in productCategory)
                                {
                                    context.ProductCategoryDetail.Remove(item);
                                    context.SaveChanges();
                                }
                            }
                            string[] splitProductIds = productIds.Split(',');
                            if (splitProductIds != null && splitProductIds.Length > 0)
                            {
                                foreach (var item in splitProductIds)
                                {
                                    if (!string.IsNullOrWhiteSpace(item))
                                    {
                                        ProductCategoryDetail productCategoryDetail = new ProductCategoryDetail();
                                        productCategoryDetail.ProductCategoryTypeFK = productCategoryType.ProductCategoryTypeId;
                                        productCategoryDetail.ProductFK             = DBHelper.ParseInt64(item);
                                        context.ProductCategoryDetail.Add(productCategoryDetail);
                                        context.SaveChanges();
                                    }
                                }
                            }
                        }

                        return(productCategoryTypeModel.ProductCategoryTypeId);
                    }
                    else
                    {
                        return(ReturnCode.NotExist.GetHashCode());
                    }
                }
                else
                {
                    return(ReturnCode.AlreadyExist.GetHashCode());
                }
            }
            catch (Exception ex)
            {
                LogHelper.ExceptionLog(ex.Message + "  :::::  " + ex.StackTrace);
                throw ex;
            }
        }