예제 #1
0
        public ActionResult Detail(string id)
        {
            try
            {
                ProductDetailViewModels model = new ProductDetailViewModels();
                if (!string.IsNullOrEmpty(id))
                {
                    var dataDetail = _fac.GetDetail(id);
                    if (dataDetail != null)
                    {
                        dataDetail.ListImages = _fac.GetListImageOfProduct(id);
                        if (dataDetail.ListImages != null)
                        {
                            dataDetail.ListImages.ForEach(x =>
                            {
                                x.ImageURL = Commons.HostImage + "Products/" + x.ImageURL;
                            });
                        }
                        dataDetail.ListImages = dataDetail.ListImages.OrderBy(x => x.ImageURL).Skip(0).Take(4).ToList();

                        var oldData = _fac.GetList().Where(x => !x.Id.Equals(id) && x.CategoryId.Equals(dataDetail.CategoryId)).OrderBy(x => x.CreatedDate).Skip(0).Take(5).ToList();
                        if (oldData != null && oldData.Any())
                        {
                            var dataImage = _fac.GetListImage();
                            oldData.ForEach(x =>
                            {
                                var _Image = dataImage.FirstOrDefault(y => y.ProductId.Equals(x.Id));
                                if (_Image != null)
                                {
                                    if (!string.IsNullOrEmpty(_Image.ImageURL))
                                    {
                                        x.ImageURL = Commons.HostImage + "Products/" + _Image.ImageURL;
                                    }
                                }
                            });
                        }

                        model.ListProduct = oldData;
                        model.Product     = dataDetail;
                        return(View(model));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                //NSLog.Logger.Error("GetDetail: ", ex);
                return(new HttpStatusCodeResult(400, ex.Message));
            }
        }
예제 #2
0
        public ActionResult Edit(string Id)
        {
            var model = GetDetail(Id);

            model.ListImages = _factory.GetListImageOfProduct(Id);
            var _OffSet = 0;

            if (model.ListImages != null && model.ListImages.Any())
            {
                model.ListImages.ForEach(x =>
                {
                    x.OffSet    = _OffSet;
                    _OffSet     = _OffSet + 1;
                    x.ImageName = " ";
                    x.ImageURL  = Commons.HostImage + "Products/" + x.ImageURL;
                });
            }
            return(PartialView("_Edit", model));
        }
예제 #3
0
        public ActionResult Delete(CMS_ProductsModels model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(PartialView("_Delete", model));
                }
                var msg = "";
                var _LstImageOfProduct = _factory.GetListImageOfProduct(model.Id);
                var result             = _factory.Delete(model.Id, ref msg);
                if (result)
                {
                    if (_LstImageOfProduct != null && _LstImageOfProduct.Any())
                    {
                        foreach (var item in _LstImageOfProduct)
                        {
                            // delete image for folder
                            if (System.IO.File.Exists(Server.MapPath("~/Uploads/Products/" + item.ImageURL)))
                            {
                                ImageHelper.Me.TryDeleteImageUpdated(Server.MapPath("~/Uploads/Products/" + item.ImageURL));
                            }
                        }
                    }
                    return(RedirectToAction("Index"));
                }

                ModelState.AddModelError("ProductCode", msg);
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(PartialView("_Delete", model));
            }
            catch (Exception ex)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(PartialView("_Delete", model));
            }
        }