示例#1
0
        public IActionResult SearchType()
        {
            ProductTypeViewModel model = new ProductTypeViewModel();

            model.productTypes = productRepository.GetProductTypeList();
            return(View(model));
        }
示例#2
0
        public IActionResult DeleteProductType(int id)
        {
            ProductType          appProductType = _unitOfWork.ProductTypes.Get(id);
            ProductTypeViewModel productTypeVM  = new ProductTypeViewModel();

            Mapper.Map <ProductType, ProductTypeViewModel> (appProductType, productTypeVM);

            if (productTypeVM == null)
            {
                return(NotFound(id));
            }

            if (_unitOfWork.Products.Find(p => p.ProductTypeId == appProductType.Id).Any())
            {
                return(BadRequest("Product type cannot be deleted. Remove all products from this product type and try again"));
            }

            _unitOfWork.ProductTypes.Remove(appProductType);

            if (_unitOfWork.SaveChanges() == 1)
            {
                return(Ok(productTypeVM));
            }
            return(BadRequest(ModelState));
        }
示例#3
0
        public IActionResult UpdateProductType(int id, [FromBody] ProductTypeViewModel productType)
        {
            if (ModelState.IsValid)
            {
                if (productType == null)
                {
                    return(BadRequest($"{nameof(productType)} cannot be null"));
                }

                ProductType appProductType = _unitOfWork.ProductTypes.Get(id);

                if (appProductType == null)
                {
                    return(NotFound(id));
                }


                Mapper.Map <ProductTypeViewModel, ProductType>(productType, appProductType);

                if (_unitOfWork.SaveChanges() == 1)
                {
                    return(Ok(productType));
                }
            }

            return(BadRequest(ModelState));
        }
        public async Task <IActionResult> UpdateProductType(int id, [FromBody] ProductTypeViewModel formdata)
        {
            try
            {
                if (formdata == null)
                {
                    return(BadRequest(new JsonResult(new { message = "object sent from client is null." })));
                }
                if (id <= 0)
                {
                    return(BadRequest(new JsonResult(new { message = "object sent from client is null." })));
                }
                if (id != formdata.Id)
                {
                    return(BadRequest(new JsonResult(new { message = "please ensure you are updating right object" })));
                }
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid model object sent from client."));
                }
                var productType   = _mapper.Map <ProductTypeDto>(formdata);
                var productTypeId = await _productTypeService.UpdateProductType(productType);

                if (productTypeId == -1)
                {
                    return(NotFound());
                }
                productType.Id = productTypeId;
                return(CreatedAtAction(nameof(GetProductType), new { id = productTypeId }, _mapper.Map <ProductTypeViewModel>(productType)));
            }
            catch (Exception e)
            {
                return(StatusCode(500, new JsonResult(new { message = $"Something went wrong inside update ProductType action: {e.Message}" })));
            }
        }
示例#5
0
        // GET: ProductTypes
        public async Task <IActionResult> Index()
        {
            var model = new ProductTypeViewModel();

            // Get line items grouped by product id, including count
            var counter = from product in _context.Products
                          group product by product.ProductTypeID into grouped
                          select new { grouped.Key, myCount = grouped.Count() };

            // Build list of Product instances for display in view
            model.GroupedProducts = await(
                from t in _context.ProductTypes
                join p in _context.Products
                on t.ProductTypeID equals p.ProductTypeID
                group new { t, p } by new { t.ProductTypeID, t.CategoryName } into grouped
                select new GroupedProducts
            {
                TypeId       = grouped.Key.ProductTypeID,
                TypeName     = grouped.Key.CategoryName,
                ProductCount = grouped.Select(x => x.p.ProductID).Count(),
                Products     = grouped.Select(x => x.p).Take(6)
            }).ToListAsync();

            return(View(model));
        }
        public async Task <IActionResult> AddProductType([FromBody] ProductTypeViewModel formdata)
        {
            try
            {
                if (formdata == null)
                {
                    return(BadRequest(new JsonResult(new { message = "object sent from client is null." })));
                }
                else if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid model object sent from client."));
                }
                var productType     = _mapper.Map <ProductTypeDto>(formdata);
                var productTypeData = await _productTypeService.AddProductType(productType);

                if (productTypeData == -1)
                {
                    return(NotFound());
                }
                productType.Id = productTypeData;
                var addedTestresult = _mapper.Map <ProductTypeViewModel>(productType);
                return(CreatedAtAction(nameof(GetProductType), new { id = productTypeData }, addedTestresult));
            }
            catch (Exception e)
            {
                return(StatusCode(500, $"Something went wrong inside add testresult action: {e.Message}"));
            }
        }
示例#7
0
        public async Task <IHttpActionResult> Post(ProductTypeViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var stf = await _productTypeService.InsertAsync(model, GetCurrentUserID());

                var resultObject = new ProductTypeViewModel()
                {
                    Name = stf.Name,
                    Code = stf.Code,
                    ID   = stf.Id,
                };
                bool de = _unitOfWorkAsync.Commit();
                return(Created(resultObject));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public IActionResult Save(ProductTypeViewModel productTypeVM)
        {
            var productType = productTypeVM.ToModel();

            _productTypeBLL.Save(productType);
            return(View(ProductTypeViewModel.FromModel(productType)));
        }
        public IActionResult Index(string sortOrder, string searchString, string currentFilter, int?page)
        {
            ViewData["NameSortParm"] = string.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }
            ViewData["CurrentFilter"] = searchString;
            ProductTypeViewModel model = new ProductTypeViewModel()
            {
                // Cheeses = CheeseData.GetAll()
                ListProductTypes = _database.Find(s => s.IsDeleted == false).ToList()
            };

            if (!string.IsNullOrEmpty(searchString))
            {
                model.ListProductTypes = model.ListProductTypes.Where(s => s.ProductTypeName.ToLower().Contains(searchString.ToLower())).ToList();
            }
            switch (sortOrder)
            {
            case "name_desc":
                model.ListProductTypes = model.ListProductTypes.OrderByDescending(s => s.ProductTypeName).ToList();
                break;
            }
            int pageSize = 5;

            return(View(PaginatedProductList <ProductType> .Create(model.ListProductTypes.AsQueryable(), page ?? 1, pageSize)));
        }
示例#10
0
        /// <summary>
        /// Add and Update view of the Model
        /// </summary>
        /// <returns></returns>
        public IActionResult Index()
        {
            ProductTypeViewModel model = new ProductTypeViewModel();

            model.productTypeMaster.IsActive = true;
            InitAccessModel(model);
            return(View(model));
        }
示例#11
0
        public int IsExists(ProductTypeViewModel prodTViewModel)
        {
            var prodType = Mapper.Map <ProductTypeViewModel, ProductType>(prodTViewModel);

            int result = _productTypeRepository.IsExists(prodType);

            return(result);
        }
示例#12
0
        public ViewProductType()
        {
            InitializeComponent();
            ProductTypeViewModel _PTVM = new ProductTypeViewModel();

            _PTVM.GetProductTypeList();
            this.DataContext = _PTVM;
        }
示例#13
0
        public async Task <IActionResult> Index()
        {
            var model = new ProductTypeViewModel(context);

            model.Products = await context.Product.ToListAsync();

            return(View(model));
        }
示例#14
0
        public ProductTypeViewModel CreateProductTypeViewModel()
        {
            ProductTypeViewModel productTypeViewModel = new ProductTypeViewModel();

            productTypeViewModel.ProductTypeListModels = getListOfProductTypesQuery.Execute();

            return(productTypeViewModel);
        }
        public IActionResult Update([FromBody] CrudViewModel <ProductTypeViewModel> payload)
        {
            ProductTypeViewModel value = payload.value;
            var result = _functionalService
                         .Update <ProductTypeViewModel, ProductType>(value, Convert.ToInt32(value.ProductTypeId));

            return(Ok());
        }
 public async Task <JsonResult> UpdateProductType([Required] ProductTypeViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(JsonModelStateErrors());
     }
     return(await JsonAsync(_crmVocabulariesService.UpdateProductTypeAsync(model)));
 }
示例#17
0
        public ActionResult CreateProductType()
        {
            var model = new ProductTypeViewModel();

            model.PageTitle = "Add product type - Mowido";

            return(View(model));
        }
示例#18
0
        public JsonResult GetDetail(int id)
        {
            ProductType productType = _productTypesRepository.GetDetail(id);

            return(Json(
                       ProductTypeViewModel.CreateFrom(productType)
                       ));
        }
示例#19
0
 public IActionResult SearchType(ProductTypeViewModel model)
 {
     if (ModelState.IsValid)
     {
         model.productTypes = productRepository.SearchProductTypes(model.Id, model.Name, model.Status);
         return(View(model));
     }
     return(RedirectToAction("ProductType", "Product"));
 }
示例#20
0
        public ProductTypeViewModel UpdateProductType(int id, ProductTypeViewModel viewModel)
        {
            var oldProductTYpe = _context.producttypes.Find(id);

            _context.Entry(oldProductTYpe).CurrentValues.SetValues(viewModel);
            _context.SaveChanges();

            return(viewModel);
        }
示例#21
0
        public ProductTypeViewModel CreateProductType(ProductTypeViewModel viewModel)
        {
            var productType = Mapper.Map <ProductTypeViewModel, producttype>(viewModel);

            _context.producttypes.Add(productType);
            _context.SaveChanges();

            return(Mapper.Map <producttype, ProductTypeViewModel>(productType));
        }
示例#22
0
 public ProductType ToProductType(ProductTypeViewModel productType)
 {
     return(new ProductType()
     {
         Id = productType.Id,
         Name = productType.Name,
         Description = productType.Description,
         AttributeTypes = productType.AttributeTypes.Select(a => ToAttributeType(a)).ToList()
     });
 }
示例#23
0
        public async Task <IActionResult> ProductType()
        {
            ProductTypeViewModel model = new ProductTypeViewModel
            {
                productTypes = await lostAndFoundType.GetProductType(),
                fLang        = _pLang.PerseLang("MasterData/ProductTypeEN.json", "MasterData/ProductTypeBN.json", Request.Cookies["lang"]),
            };

            return(View(model));
        }
        public IActionResult Edit(int id)
        {
            var productTypeVM = new ProductTypeViewModel();

            if (id > 0)
            {
                productTypeVM = _productTypeBLL.GetAll().Where(p => p.Id == id).Select(ProductTypeViewModel.FromModel).FirstOrDefault();
            }
            return(View("Create", productTypeVM));
        }
示例#25
0
        /// <summary>
        /// Delete an entity.
        /// </summary>
        /// <param name="model"></param>
        public void Delete(ProductTypeViewModel model)
        {
            var entity = model.ToEntity();

            this._ProductTypesRepository.Delete(entity);

            #region Commit Changes
            this._unitOfWork.Commit();
            #endregion
        }
        public IActionResult Insert(ProductTypeViewModel productType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var savedProductType = _productTypeService.Insert(Mapper.Instance.ToProductType(productType));

            return(Ok(Mapper.Instance.ToProductTypeViewModel(savedProductType)));
        }
示例#27
0
 public IActionResult DeleteAProductType(ProductTypeViewModel model)
 {
     if (ModelState.IsValid)
     {
         if (model.Id > 0)
         {
             productRepository.DeleteAProductType(model.Id);
         }
     }
     return(RedirectToAction("ProductType", "Product"));
 }
示例#28
0
        public bool Update(ProductTypeViewModel model)
        {
            var data = Find(model.ID);

            if (data != null)
            {
                data.Name             = model.Name;
                data.Code             = model.Code;
                data.LastModifiedDate = DateTime.Now;
            }
            return(true);
        }
示例#29
0
 public IActionResult AddUpdate(ProductTypeViewModel model)
 {
     if (ModelState.IsValid)
     {
         return(Json(_interface.AddUpdate(model.productTypeMaster)));
     }
     else
     {
         resp.Message = Constants.ControllerMessage.All_Fields_Mandatory;
         return(Json(resp));
     }
 }
示例#30
0
        public async Task <ProductTypeViewModel> UpdateAsync(ProductTypeViewModel model)
        {
            try
            {
                await Task.Run(() => Update(model));

                return(model);
            }
            catch (Exception e)
            {
                throw (e);
            }
        }