示例#1
0
        // PUT api/suppliers/id
        public IHttpActionResult PutSupllier(int id, [FromBody] SupplierModelView supplier)
        {
            var supOld = supplierService.GetById(id);

            if (supOld == null)
            {
                return(NotFound());
            }

            if (supplier == null)
            {
                return(BadRequest());
            }

            var newSup = new SupplierDTO
            {
                Id          = id,
                CompanyName = supplier.CompanyName,
                Products    = mapper.Map <ICollection <ProductModelView>, ICollection <ProductDTO> >(supplier.Products)
            };

            supplierService.Update(newSup);

            return(Ok(new { Message = $"A supplier {supplier.CompanyName} has updated" }));
        }
示例#2
0
        public ActionResult Show()
        {
            SupplierModelView supplierVm = new SupplierModelView();

            supplierVm.Suppliers = supplierManager.GetAll();


            return(View(supplierVm));
        }
示例#3
0
        public ActionResult Delete(int Id)
        {
            SupplierModelView supplierVm = new SupplierModelView();
            Supplier          supplier   = new Supplier();

            supplier = supplierManager.GetById(Id);

            supplierVm = Mapper.Map <SupplierModelView>(supplier);

            return(View(supplierVm));
        }
 public JsonResponse Post([FromBody] SupplierModelView supplier)
 {
     try
     {
         _context.CreateSupplier(supplier);
         return(new JsonResponse(1, "", null));
     }
     catch (Exception ex)
     {
         return(new JsonResponse(-1, ex.Message, null));
     }
 }
示例#5
0
        // POST api/suppliers/id
        public IHttpActionResult PostSupplier([FromBody] SupplierModelView supplier)
        {
            if (!ModelState.IsValid || supplier == null)
            {
                return(BadRequest());
            }

            var model = new SupplierDTO
            {
                CompanyName = supplier.CompanyName,
                Products    = mapper.Map <ICollection <ProductModelView>, ICollection <ProductDTO> >(supplier.Products)
            };

            supplierService.Create(model);

            return(Ok(new { Message = $"The new supplier {supplier.CompanyName} has created" }));
        }
示例#6
0
        public ActionResult Add(SupplierModelView supplierVm)
        {
            if (ModelState.IsValid)
            {
                var supplier = Mapper.Map <Supplier>(supplierVm);

                if (supplierManager.Add(supplier))
                {
                    ViewBag.SuccessMsg = "Supplier Added";
                }
                else
                {
                    ViewBag.FailMsg = "Failed";
                }
            }
            else
            {
                ViewBag.FailMsg = "Upps!Something Wrong";
            }
            return(View(supplierVm));
        }
示例#7
0
        public ActionResult Show(SupplierModelView supplierVm)
        {
            var suppliers = supplierManager.GetAll();

            if (supplierVm.Code != null)
            {
                suppliers = suppliers.Where(c => c.Code.ToLower().Contains(supplierVm.Code.ToLower())).ToList();
            }

            if (supplierVm.SupplierName != null)
            {
                suppliers = suppliers.Where(c => c.SupplierName.ToLower().Contains(supplierVm.SupplierName.ToLower())).ToList();
            }

            if (supplierVm.Email != null)
            {
                suppliers = suppliers.Where(c => c.Email.ToLower().Contains(supplierVm.Email.ToLower())).ToList();
            }
            supplierVm.Suppliers = suppliers;

            return(View(supplierVm));
        }
示例#8
0
        public ActionResult Delete(SupplierModelView supplierVm)
        {
            if (ModelState.IsValid)
            {
                var supplier = Mapper.Map <Supplier>(supplierVm);

                if (supplierManager.Delete(supplier))
                {
                    ViewBag.SuccessMsg = "Deleted!";
                }
                else
                {
                    ViewBag.ErrorMsg = "Failed!";
                }
            }
            else
            {
                ViewBag.ErrorMsg = "Validation!";
            }


            return(RedirectToAction("Show", "Supplier"));
        }
示例#9
0
        //public object getProducts()
        //{
        //    var collection = database.GetCollection<ProductModelView>("Products");

        //    List<ProductModelView> products = collection.Find(new BsonDocument()).ToList();
        //    return products;
        //}

        public void CreateSupplier(SupplierModelView supplier)
        {
            var collection = database.GetCollection <SupplierModelView>("Supplier");

            collection.InsertOne(supplier);
        }
示例#10
0
        public ActionResult Add()
        {
            SupplierModelView supplierVm = new SupplierModelView();

            return(View(supplierVm));
        }