Ejemplo n.º 1
0
        public async Task DeleteProductCategoryMapping(ProductCategoryModel productCategory)
        {
            if (productCategory == null)
            {
                throw new ArgumentNullException("ProductCategoryMapping");
            }

            await _productCategoryRepository.Delete(_mapper.Map <ProductCategoryMapping>(productCategory));
        }
Ejemplo n.º 2
0
        public ActionResult EditProductCategory(ProductCategoryModel productCategoryModel, HttpPostedFileBase ImageFile)
        {
            ResponseModel _response = new ResponseModel();

            if (ModelState.IsValid)
            {
                try
                {
                    // Image byte converter
                    if (ImageFile != null)
                    {
                        productCategoryModel.DocProductCategory = new DocumentModel();
                        using (var memoryStream = new MemoryStream())
                        {
                            ImageFile.InputStream.CopyTo(memoryStream);
                            byte[] imageBytes = memoryStream.ToArray();
                            productCategoryModel.DocProductCategory.Filebytes      = imageBytes;
                            productCategoryModel.DocProductCategory.FileName       = ImageFile.FileName;
                            productCategoryModel.DocProductCategory.FileExtenstion = Path.GetExtension(ImageFile.FileName);
                        }
                    }
                    using (var client = new HttpClient())
                    {
                        // Get UserId
                        productCategoryModel.ModifiedBy   = UserAuthenticate.UserId;
                        productCategoryModel.ModifiedDate = DateTime.Now;
                        string apiURL = BaseUrl + "api/ApiProduct/EditProductCategory";
                        client.BaseAddress = new Uri(apiURL);
                        client.DefaultRequestHeaders.Accept.Clear();
                        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                        HttpResponseMessage response = client.PostAsJsonAsync(apiURL, productCategoryModel).Result;
                        if (response.IsSuccessStatusCode)
                        {
                            _response = (new JavaScriptSerializer()).Deserialize <ResponseModel>(response.Content.ReadAsStringAsync().Result);
                            // Return error message
                            if (_response.Type.ToLower() == "error")
                            {
                                ViewBag.Error = _response.Message;
                                return(View(productCategoryModel));
                            }
                            ViewBag.Success = _response.Message;
                            ModelState.Clear();
                        }
                        else
                        {
                            ViewBag.Error = "Error:" + _response.Message;
                        }
                    }
                }
                catch (Exception ex)
                {
                    ViewBag.Error = "Error:" + ex.Message;
                }
            }
            return(View());
        }
Ejemplo n.º 3
0
        public ActionResult New()
        {
            var Category            = db.Category.ToList();
            ProductCategoryModel pc = new ProductCategoryModel()
            {
                Category = Category
            };

            return(View(pc));
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="productcategory"></param>
        /// <returns></returns>
        public static ProductCategory ProductCategoryModelToProductCategoryMapper(this ProductCategoryModel productcategorymodel)
        {
            ProductCategory productcategory = new ProductCategory()
            {
                ProductCategoryID = productcategorymodel.ProductCategoryID,
                Description       = productcategorymodel.Description
            };

            return(productcategory);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="productcategory"></param>
        /// <returns></returns>
        public static ProductCategoryModel ProductCategoryToProductCategoryModelMapper(this ProductCategory productcategory)
        {
            ProductCategoryModel productcategorymodel = new ProductCategoryModel()
            {
                ProductCategoryID = productcategory.ProductCategoryID,
                Description       = productcategory.Description
            };

            return(productcategorymodel);
        }
Ejemplo n.º 6
0
        public ActionResult UpdateCategory(int id, ProductCategoryModel categorydata)
        {
            ProductCategory category = Mapper.Map <ProductCategoryModel, ProductCategory>(categorydata);

            if (inventoryBusinessLogic.ToUpdateProductCategory(category) == true)
            {
                return(RedirectToAction("ProductCategoryData"));
            }
            return(View());
        }
Ejemplo n.º 7
0
        private ProductCategoryModel convertCategoryToCategoryModel(ProductCategory productCategory)
        {
            var model = new ProductCategoryModel();

            model.Id       = productCategory.ID;
            model.Name     = productCategory.Name;
            model.ImageURL = productCategory.ImagePath;

            return(model);
        }
 public ActionResult Edit(ProductCategoryModel productCategory)
 {
     if (ModelState.IsValid)
     {
         ProductCategoryModel ProductCategoryEdit = Services.ProductCategoryService.Edit(productCategory);
         TempData["Success"] = "Data Saved Successfully!";
         return(RedirectToAction("Index", "ProductCategory"));
     }
     return(View(productCategory));
 }
Ejemplo n.º 9
0
        public ProductCategoryModel EntityToModel(Category entity, List <Product> entity2)
        {
            ProductCategoryModel    res     = new ProductCategoryModel();
            SidebarCategoriesMapper mapper2 = new SidebarCategoriesMapper();
            ProductsMapper          mapper  = new ProductsMapper();

            res.Category = mapper2.EntityToModel(entity);
            res.Items    = mapper.EntityToModel(entity2);
            return(res);
        }
Ejemplo n.º 10
0
        public ActionResult Add()
        {
            var Category = db.Category.ToList();
            ProductCategoryModel productCategoryModel = new ProductCategoryModel
            {
                category = Category
            };

            return(View(productCategoryModel));
        }
 public ActionResult DeleteConfirmed(ProductCategoryModel productCategory)
 {
     if (productCategory.Id > 0)
     {
         ProductCategoryModel ProductCategoryDelete = Services.ProductCategoryService.Delete(productCategory);
         TempData["Success"] = "Data Deleted Successfully!";
         return(RedirectToAction("Index", "ProductCategory"));
     }
     return(View(productCategory));
 }
Ejemplo n.º 12
0
        public async Task <ProductCategoryModel> GetProductCategoryDetail(int id)
        {
            ProductCatogery productCatogery = await _productRepository.GetProductCategoryDetail(id);

            ProductCategoryModel productCategoryModel = new ProductCategoryModel();

            productCategoryModel.Id          = productCatogery.Id;
            productCategoryModel.Name        = productCatogery.Name;
            productCategoryModel.Description = productCatogery.Description;
            return(productCategoryModel);
        }
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            ProductCategoryModel ProductCategoryModelById = Services.ProductCategoryService.GetById(id);

            return(View(ProductCategoryModelById));
        }
Ejemplo n.º 14
0
        public ActionResult Add(ProductCategoryModel productCategoryModel)
        {
            if (ModelState.IsValid)
            {
                db.Product.Add(productCategoryModel.product);
                db.SaveChanges();
                return(Json(new { restult = 1 }));
            }

            return(Json(new { restult = 0 }));
        }
Ejemplo n.º 15
0
        public async Task <ActionResult> Edit([Bind(Include = "ProductId,Name")] ProductCategoryModel productCategoryModel)
        {
            if (ModelState.IsValid)
            {
                var category = Mapper.Map <ProductCategoryModel, ProductCategory>(productCategoryModel);
                await categoryService.CategoryEdit(category);

                return(RedirectToAction("Index"));
            }
            return(View(productCategoryModel));
        }
        public ActionResult List()
        {
            if (!_permissionService.Authorize("ManageProducts"))
            {
                return(AccessDeniedView());
            }

            var model = new ProductCategoryModel();

            return(View(model));
        }
Ejemplo n.º 17
0
        public ActionResult Create([Bind(Include = "prodCategoryID,categoryName")] ProductCategoryModel productCategory)
        {
            if (ModelState.IsValid)
            {
                Context.ProductCategoryModelSet.Add(productCategory);
                Context.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(productCategory));
        }
Ejemplo n.º 18
0
 //Add ==>time of submit
 public ActionResult Add(ProductCategoryModel p, HttpPostedFileBase fileObj)
 {
     if (fileObj != null)
     {
         p.ProductObj.Image = p.ProductObj.Id + fileObj.FileName + Path.GetExtension(fileObj.FileName);
         fileObj.SaveAs(Server.MapPath("//Content//ProductImages//" + p.ProductObj.Image));
     }
     repository.Add(p.ProductObj);
     repository.Commit();
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 19
0
        public static int CreateCategory(string categoryName)
        {
            ProductCategoryModel data = new ProductCategoryModel
            {
                CategoryName = categoryName
            };

            string sql = @"insert into dbo.Category(CategoryName) values (@CategoryName); SELECT CAST(SCOPE_IDENTITY() as int)";

            return(SqlDataAccess.SaveDataGiveID(sql, data));
        }
Ejemplo n.º 20
0
        public static int SaveNewCategoryName(string categoryName)
        {
            ProductCategoryModel data = new ProductCategoryModel
            {
                CategoryName = categoryName
            };

            string sql = @"update dbo.Category CategoryName = @CategoryName";

            return(SqlDataAccess.SaveData(sql, data));
        }
Ejemplo n.º 21
0
        public ActionResult Details(int id)
        {
            var Product             = db.Product.Single(c => c.id == id);
            var Category            = db.Category.ToList();
            ProductCategoryModel pc = new ProductCategoryModel()
            {
                Category = Category,
                Product  = Product
            };

            return(View(pc));
        }
Ejemplo n.º 22
0
        public ActionResult Update(int id)
        {
            var Category = db.Category.ToList();
            var Product  = db.Product.SingleOrDefault(m => m.id == id);
            ProductCategoryModel productCategoryModel = new ProductCategoryModel
            {
                category = Category,
                product  = Product
            };

            return(View(productCategoryModel));
        }
Ejemplo n.º 23
0
        //convert ProductCategory tu csdl vao model ProductCategoryModel
        #region --Private----
        private ProductCategoryModel convertCategoryToCategoryModel(ProductCategory productCategory)
        {
            //chuyen doi du lieu tu DB sang model (file Models/Products)
            var model = new ProductCategoryModel();

            //lay Id trong csdl
            model.Id = productCategory.ID;
            //lay name trong csdl
            model.Name = productCategory.Name;

            return(model);
        }
Ejemplo n.º 24
0
 public ActionResult Update_PostCategory(int id, ProductCategoryModel inventoryModel)
 {
     if (ModelState.IsValid)
     {
         var registration = Mapper.Map <ProductCategoryModel, ProductCategory>(inventoryModel);
         if (userManager.ToUpdateProductCategory(registration) == true)
         {
             return(RedirectToAction("ProductCategoryData"));
         }
     }
     return(View());
 }
        public ActionResult Create(ProductCategoryModel productCategory)
        {
            var errors = ModelState.Values.SelectMany(v => v.Errors);

            if (ModelState.IsValid)
            {
                ProductCategoryModel ProductCategoryCreate = Services.ProductCategoryService.Create(productCategory);
                TempData["Success"] = "Data Saved Successfully!";
                return(RedirectToAction("Index", "ProductCategory"));
            }
            return(View(productCategory));
        }
Ejemplo n.º 26
0
        public async Task <List <ProductCategoryModel> > UpdateProductCategoryDetail(ProductCategoryModel productCategoryModel)
        {
            ProductCatogery productCatogery = await _productRepository.GetProductCategoryDetail(productCategoryModel.Id);

            productCatogery.Name        = productCategoryModel.Name;
            productCatogery.Description = productCategoryModel.Description;
            productCatogery.CreatedBy   = 5;
            productCatogery.CreatedByTs = DateTime.Now;
            await _productRepository.UpdateProductCategoryDetail(productCatogery);

            return(await GetProductCategoryList());
        }
Ejemplo n.º 27
0
 public async Task <ActionResult> AddCategory(OutModels.Models.ProductCat cat)
 {
     try
     {
         ProductCategoryModel pcm = (ProductCategoryModel)_mapper.Map <OutModels.Models.ProductCat, ProductCategoryModel>(cat);
         return(new JsonResult(await this._repository.Insert(pcm)));
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
 /// <summary>
 /// Associate a product category(if one is selected) to the new created product
 /// </summary>
 private void AssociateProductCategory(ProductModel createdproduct)
 {
     if (ProductCategoryComboBox.SelectedItem != null)
     {
         ProductCategoryModel prodCategory = new ProductCategoryModel
         {
             CategoryId = ((CategoryModel)ProductCategoryComboBox.SelectedItem).Id,
             ProductId  = createdproduct.Id
         };
         GlobalConfig.Connection.CreateProductCategory(prodCategory);
     }
 }
Ejemplo n.º 29
0
        public ActionResult Edit([Bind(Include = "prodCategoryID,categoryName")] ProductCategoryModel productCategory)
        {
            if (ModelState.IsValid)
            {
                Context.Entry(productCategory).State = EntityState.Modified;
                Context.SaveChanges();
                ViewBag.result = "Category " + productCategory.categoryName + " Updated Succesfully!";
                return(View(productCategory));
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 30
0
        public HttpResponseMessage CreateProductCategory(ProductCategoryModel productCategoryModel)
        {
            ResponseModel _response    = new ResponseModel();
            var           _getCategory = _productCategoryRepository.FindBy(x => x.ProductCategoryName.Trim().ToLower() == productCategoryModel.ProductCategoryName.Trim().ToLower() && x.Status == (int)Status.Active && x.IsDeleted == false).FirstOrDefault();

            if (_getCategory != null)
            {
                _response.Type    = "error";
                _response.Message = "Company already Exist";
                return(Request.CreateResponse(HttpStatusCode.OK, _response));
            }

            var model = Mapper.Map <ProductCategoryModel, ProductCategory>(productCategoryModel);

            model.CreatedDate = DateTime.Now;
            model.Status      = 1;
            model.IsDeleted   = false;
            var Result = _productCategoryRepository.CreateProductCategory(model);

            if (Result != null)
            {
                // For Uploading image ----
                if (productCategoryModel.DocProductCategory != null)
                {
                    UploadDocumentModel UploadDocument = new UploadDocumentModel();
                    UploadDocument.documents    = new List <DocumentModel>();
                    UploadDocument.ImageSize    = 250;
                    UploadDocument.ImageQuality = 250;
                    UploadDocument.documents.Add(productCategoryModel.DocProductCategory);
                    List <string> uploadedFileName = SavePicture(UploadDocument);
                    if (uploadedFileName.Count > 0)
                    {
                        ProductCategory _productCategory = _productCategoryRepository.FindBy(x => x.ProductCategoryId == Result.ProductCategoryId).FirstOrDefault();
                        if (_productCategory != null)
                        {
                            _productCategory.ProductCategoryImagePath = uploadedFileName[0].ToString();
                            _productCategoryRepository.Update(_productCategory);
                            _productCategoryRepository.SaveChanges();
                        }
                    }
                }

                _response.Type    = "success";
                _response.Message = "Company created successfully";
                return(Request.CreateResponse(HttpStatusCode.OK, _response));
            }
            else
            {
                _response.Type    = "error";
                _response.Message = "Something went wrong";
                return(Request.CreateResponse(HttpStatusCode.OK, _response));
            }
        }