コード例 #1
0
        public ActionResult Add_Material(long?pcId)
        {
            if (!pcId.HasValue)
            {
                return(RedirectToAction("Index", "ProductCategory", new { }));
            }

            var pc = Db.Select <Product_Category>(x => x.Where(y => (y.Id == pcId))).FirstOrDefault();

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

            ProductCategoryMaterial model = new ProductCategoryMaterial()
            {
                Id = 0,
                ProductCategoryId   = pc.Id,
                ProductCategoryName = pc.Name
            };

            model.Order = model.GetOrderNewLast();

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

            return(View(model));
        }
コード例 #2
0
        public ActionResult Move_Material(long id, int move)
        {
            try
            {
                var e = Db.SelectParam <ProductCategoryMaterial>(m => (m.Id == id)).FirstOrDefault();

                var a = new List <ProductCategoryMaterial>();

                var t = new ProductCategoryMaterial();

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

                    if (a.Count != 0)
                    {
                        t = a.LastOrDefault();
                    }
                }
                else
                {
                    a = Db.Where <ProductCategoryMaterial>(m => (m.ProductCategoryId == e.ProductCategoryId && 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 <ProductCategoryMaterial>(t);

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

            return(Json(null, JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
        public ActionResult Update_Material(ProductCategoryMaterial model, string IsPresentive, string IsActive)
        {
            model.IsPresentive = IsPresentive != null ? true : false;

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

            ProductCategoryMaterial modelUpdated = new ProductCategoryMaterial();

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

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

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

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

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

            model.SEO = model.GetSEO();

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

                model.CreatedOn = DateTime.Now;

                Db.Insert <ProductCategoryMaterial>(model);

                model.Id = Db.GetLastInsertId();

                SetOrderMaterial(model.Id, model.Order);

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

                modelUpdated.SEO = model.SEO;

                modelUpdated.Desc = model.Desc;

                modelUpdated.Order = model.Order;

                modelUpdated.IsPresentive = model.IsPresentive;

                modelUpdated.IsActive = model.IsActive;

                modelUpdated.LastUpdatedBy = AuthenticatedUserID;

                modelUpdated.LastUpdatedOn = DateTime.Now;

                Db.Update <ProductCategoryMaterial>(modelUpdated);

                SetOrderMaterial(modelUpdated.Id, modelUpdated.Order);

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

            return(RedirectToAction("Detail", "ProductCategory", new { id = model.ProductCategoryId }));
        }