コード例 #1
0
        public IActionResult Add(VMProduct vmproduct)
        {
            TbProduct product = mapper.Map <VMProduct, TbProduct>(vmproduct);

            unitOfWork.Products.Add(product);
            unitOfWork.Complete();
            vmproduct.Id = product.Id;
            return(Ok(vmproduct));
        }
コード例 #2
0
        public ActionResult Add()
        {
            VMProduct p = new VMProduct();
            //p.ProductModels = ProductModelDAL.GetList();
            Guid teknolojiID = Guid.Parse("35391ff3-c30d-4a6a-b30b-14079eaaa455");

            p.Categories = CategoryDAL.GetList(x => x.SubCategoryID == teknolojiID);
            return(View(p));
        }
コード例 #3
0
        public ActionResult Add(VMProduct model)
        {
            Product yeniUrun = new Product();

            ProductModel pm = ProductModelDAL.Get(x => x.ModelID == model.ModelID);

            yeniUrun.ModelID      = pm.ModelID;
            yeniUrun.Description  = model.Description;
            yeniUrun.IsActive     = true;
            yeniUrun.ProductID    = Guid.NewGuid();
            yeniUrun.ProductName  = model.ProductName;
            yeniUrun.UnitPrice    = model.UnitPrice;
            yeniUrun.UnitsInStock = model.UnitsInStock;
            yeniUrun.ViewCount    = 0;

            Guid     cID = pm.CategoryID;
            Category c   = CategoryDAL.Get(x => x.CategoryID == cID);

            foreach (Property item in c.Properties)
            {
                string valProp = Request.Form[item.PropertyID.ToString()];
                if (valProp != null)
                {
                    ProductTechnicProperty temp = new ProductTechnicProperty();

                    temp.PropertyID        = item.PropertyID;
                    temp.PropertyValue     = valProp;
                    temp.ProductPropertyID = Guid.NewGuid();
                    yeniUrun.ProductTechnicProperties.Add(temp);
                }
            }

            foreach (HttpPostedFileBase item in model.Picture)
            {
                if (item != null)
                {
                    string pic  = System.IO.Path.GetFileName(item.FileName);
                    string path = System.IO.Path.Combine(Server.MapPath("~/Assets/img/products"), pic);
                    // file is uploaded
                    item.SaveAs(path);

                    ProductPicture temp = new ProductPicture();

                    temp.ProductPictureID = Guid.NewGuid();
                    temp.PicturePath      = item.FileName;
                    temp.IsActive         = true;
                    yeniUrun.ProductPictures.Add(temp);
                }
            }

            ProductDAL.Add(yeniUrun);


            return(RedirectToAction("Add"));
        }
コード例 #4
0
        public IActionResult Edit(VMProduct vmproduct)
        {
            TbProduct product = unitOfWork.Products.Get(vmproduct.Id);

            if (product == null)
            {
                return(NotFound());
            }
            product = mapper.Map <VMProduct, TbProduct>(vmproduct);
            unitOfWork.Complete();
            return(Ok(vmproduct));
        }
コード例 #5
0
        public ActionResult Create(VMProduct paramModel)
        {
            try
            {
                ProductRepo.Message = string.Empty;

                //Create auto generate product_code
                using (var db = new Markom_IDLEEntities())
                {
                    string    nol    = "";
                    m_product cek    = db.m_product.OrderByDescending(x => x.code).First();
                    int       simpan = int.Parse(cek.code.Substring(3));
                    simpan++;
                    for (int i = simpan.ToString().Length; i < 4; i++)
                    {
                        nol = nol + "0";
                    }
                    paramModel.code = "PR" + nol + simpan;
                }

                paramModel.created_by   = "Administrator";
                paramModel.created_date = DateTime.Now;
                paramModel.is_delete    = false;

                if (null == paramModel.name)
                {
                    ProductRepo.Message = "Anda belum memasukan semua data. Silahkan ulangi kembali";
                }
                if (string.IsNullOrEmpty(ProductRepo.Message))
                {
                    return(Json(new
                    {
                        success = ProductRepo.Insert(paramModel),
                        message = paramModel.code
                    }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { success = false, message = ProductRepo.Message },
                                JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception hasError)
            {
                return(Json(new { success = false, message = hasError.Message },
                            JsonRequestBehavior.AllowGet));
            }
        }
コード例 #6
0
 public ActionResult Delete(VMProduct paramModel)
 {
     try
     {
         return(Json(new
         {
             success = ProductRepo.Delete(paramModel),
             message = ProductRepo.Message
         }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception hasError)
     {
         return(Json(new { success = false, message = hasError.Message },
                     JsonRequestBehavior.AllowGet));
     }
 }
コード例 #7
0
        public static VMProduct GetVMProduct(Product P)
        {
            if (P.IdCategory != null && P.IdSupplier != null)
            {
                erp_dataEntities2 db    = new erp_dataEntities2();
                VMProduct         VMP   = new VMProduct();
                decimal           decId = Convert.ToDecimal(P.IdCategory);
                VMP.Category       = db.Categories.Where(x => x.Id == decId).FirstOrDefault().Title;
                VMP.Supplier       = db.Suppliers.Where(x => x.Id == P.IdSupplier).FirstOrDefault().Title;
                VMP.LastUpdateDate = P.LastUpdateDate;
                VMP.Price          = P.Price;
                VMP.Title          = P.Title;
                VMP.Code           = P.Code;
                VMP.Id             = P.Id;
                VMP.Amount         = P.Amount;
                return(VMP);
            }

            return(null);
        }
コード例 #8
0
        public static bool Update(VMProduct paramModel)
        {
            bool result = true;

            try
            {
                using (var db = new Markom_IDLEEntities())
                {
                    m_product a = db.m_product.Where(o => o.id == paramModel.id).FirstOrDefault();
                    if (a != null)
                    {
                        a.name         = paramModel.name;
                        a.description  = paramModel.description;
                        a.updated_by   = paramModel.updated_by;
                        a.updated_date = paramModel.updated_date;

                        db.SaveChanges();
                    }
                    else
                    {
                        result = false;
                    }
                }
            }

            catch (Exception hasError)
            {
                result = false;
                if (hasError.Message.ToLower().Contains("inner exception"))
                {
                    Message = hasError.InnerException.InnerException.Message;
                }
                else
                {
                    Message = hasError.Message;
                }
            }
            return(result);
        }
コード例 #9
0
        public static VMProduct GetDetailById(int Id)
        {
            VMProduct result = new VMProduct();

            using (var db = new Markom_IDLEEntities())
            {
                result = (from a in db.m_product
                          where a.id == Id
                          select new VMProduct
                {
                    id = a.id,
                    code = a.code,
                    name = a.name,
                    description = a.description,
                    is_delete = a.is_delete,
                    created_by = a.created_by,
                    created_date = a.created_date,
                    updated_by = a.updated_by,
                    updated_date = a.updated_date
                }).FirstOrDefault();
            }
            return(result);
        }
コード例 #10
0
        public static List <VMProduct> GetListVMProducts(List <Product> list)
        {
            erp_dataEntities2 db          = new erp_dataEntities2();
            List <Product>    CurrentList = new List <Product>();
            List <VMProduct>  ListVM      = new List <VMProduct>();

            if (list != null)
            {
                CurrentList = list;
            }
            else
            {
                CurrentList = db.Products.ToList();
            }


            foreach (Product P in CurrentList)
            {
                if (P.IdCategory != null && P.IdSupplier != null)
                {
                    VMProduct VMP   = new VMProduct();
                    decimal   decId = Convert.ToDecimal(P.IdCategory);
                    VMP.Category       = db.Categories.Where(x => x.Id == decId).FirstOrDefault().Title;
                    VMP.Supplier       = db.Suppliers.Where(x => x.Id == P.IdSupplier).FirstOrDefault().Title;
                    VMP.LastUpdateDate = P.LastUpdateDate;
                    VMP.Price          = P.Price;
                    VMP.Title          = P.Title;
                    VMP.Code           = P.Code;
                    VMP.Id             = P.Id;
                    VMP.Amount         = P.Amount;

                    ListVM.Add(VMP);
                }
            }

            return(ListVM);
        }