Ejemplo n.º 1
0
        public ActionResult Add_MaterialDetail(long?materialId)
        {
            if (!materialId.HasValue)
            {
                return(RedirectToAction("Index", "ProductCategory", new { }));
            }

            var material = Db.Select <ProductCategoryMaterial>(x => x.Where(y => (y.Id == materialId))).FirstOrDefault();

            if (material == null)
            {
                return(RedirectToAction("Index", "ProductCategory", new { }));
            }

            ProductCategoryMaterialDetail model = new ProductCategoryMaterialDetail()
            {
                Id = 0,
                ProductCategoryMaterialId   = material.Id,
                ProductCategoryMaterialName = material.Name
            };

            model.Order = model.GetOrderNewLast();

            model.ProductCategoryName = model.GetProductCategoryName();

            if (model.Order == 1)
            {
                model.IsPresentive = true;
            }

            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult Move_MaterialDetail(long id, int move)
        {
            try
            {
                var e = Db.SelectParam <ProductCategoryMaterialDetail>(m => (m.Id == id)).FirstOrDefault();

                var a = new List <ProductCategoryMaterialDetail>();

                var t = new ProductCategoryMaterialDetail();

                if (move == 1)
                {
                    a = Db.Where <ProductCategoryMaterialDetail>(m => (m.ProductCategoryMaterialId == e.ProductCategoryMaterialId && m.Order < e.Order)).OrderBy(m => (m.Order)).ToList();

                    if (a.Count != 0)
                    {
                        t = a.LastOrDefault();
                    }
                }
                else
                {
                    a = Db.Where <ProductCategoryMaterialDetail>(m => (m.ProductCategoryMaterialId == e.ProductCategoryMaterialId && m.Order > e.Order)).OrderBy(m => (m.Order)).ToList();

                    if (a.Count != 0)
                    {
                        t = a.FirstOrDefault();
                    }
                }

                if (t.Id > 0)
                {
                    int i = t.Order;

                    t.Order = e.Order;

                    e.Order = i;

                    Db.Update <ProductCategoryMaterialDetail>(t);

                    Db.Update <ProductCategoryMaterialDetail>(e);
                }
            }
            catch (Exception ex)
            {
                return(JsonError(ex.Message));
            }

            return(Json(null, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 3
0
        public ActionResult Update_MaterialDetail(ProductCategoryMaterialDetail model, IEnumerable <HttpPostedFileBase> Thumbnail, string IsPresentive, string IsActive)
        {
            model.IsPresentive = IsPresentive != null ? true : false;

            model.IsActive = IsActive != null ? true : false;

            ProductCategoryMaterialDetail modelUpdated = new ProductCategoryMaterialDetail();

            if (model.Id > 0)
            {
                modelUpdated = Db.Select <ProductCategoryMaterialDetail>(x => x.Where(y => (y.Id == model.Id))).FirstOrDefault();

                if (modelUpdated == null)
                {
                    ViewBag.Error = "Please don't try to hack us";

                    return(View("Add_MaterialDetail", model));
                }
            }

            if (string.IsNullOrEmpty(model.Name))
            {
                ViewBag.Error = "Please enter field » Name";

                return(View("Add_MaterialDetail", model));
            }

            if (Thumbnail != null && Thumbnail.Count() > 0 && Thumbnail.First() != null)
            {
                model.Thumbnail = UploadFile(model.Id, CurrentUser.UserName, "category_material", Thumbnail);
            }
            else
            {
                model.Thumbnail = modelUpdated.Thumbnail;
            }

            if (model.Id == 0)
            {
                model.CreatedBy = AuthenticatedUserID;

                model.CreatedOn = DateTime.Now;

                Db.Insert <ProductCategoryMaterialDetail>(model);

                model.Id = Db.GetLastInsertId();

                SetOrderMaterialDetail(model.Id, model.Order);

                SetPresentiveMaterialDetail(model.Id, model.IsPresentive);
            }
            else
            {
                modelUpdated.Name = model.Name;

                modelUpdated.Thumbnail = model.Thumbnail;

                modelUpdated.Order = model.Order;

                modelUpdated.IsPresentive = model.IsPresentive;

                modelUpdated.IsActive = model.IsActive;

                modelUpdated.LastUpdatedBy = AuthenticatedUserID;

                modelUpdated.LastUpdatedOn = DateTime.Now;

                Db.Update <ProductCategoryMaterialDetail>(modelUpdated);

                SetOrderMaterialDetail(modelUpdated.Id, modelUpdated.Order);

                SetPresentiveMaterialDetail(modelUpdated.Id, modelUpdated.IsPresentive);
            }

            return(RedirectToAction("Detail_Material", "ProductCategory", new { id = model.ProductCategoryMaterialId }));
        }