Пример #1
0
 public ActionResult Create()
 {
     //this is bad practice and should be replaces with view model
     ViewBag.CategoryList = new SelectList(_categoryServices.GetAllCategories(), "Id", "Name");
     ViewBag.ManufacList  = new SelectList(_manufacturerServices.GetAllManufacturers(), "Id", "Name");
     ViewBag.SupplierList = new SelectList(_supplierServices.GetAllSuppliers(), "Id", "Name");
     return(View());
 }
        public IActionResult GetAll()
        {
            IEnumerable <CategoryMaster> category = _categoryServices.GetAllCategories();
            List <CategoryViewModel>     roleVM   = new List <CategoryViewModel>();

            try
            {
                if (category != null)
                {
                    foreach (CategoryMaster r in category)
                    {
                        MapperConfiguration config = new MapperConfiguration(cfg =>
                        {
                            cfg.CreateMap <CategoryMaster, CategoryViewModel>();
                        });
                        IMapper           mapper = config.CreateMapper();
                        CategoryViewModel dest   = Mapper.Map <CategoryMaster, CategoryViewModel>(r);
                        roleVM.Add(dest);
                    }
                }
                return(Ok(roleVM));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #3
0
        // GET: api/Categories
        public IEnumerable <CategoryEntity> GetAllCategories()
        {
            var categoryEntities = categoryServices.GetAllCategories();

            if (categoryEntities != null)
            {
                if (categoryEntities.Any())
                {
                    return(categoryEntities);
                }
            }
            return(null);
        }
Пример #4
0
        // GET: api/Categories
        public IEnumerable <CategoryViewModel> GetAllCategories()
        {
            var categoryEntities = categoryServices.GetAllCategories();

            if (categoryEntities != null)
            {
                if (categoryEntities.Any())
                {
                    Mapper.Initialize(cfg => { cfg.CreateMissingTypeMaps = true; cfg.CreateMap <CategoryEntity, CategoryViewModel>(); });
                    var categories = Mapper.Map <IEnumerable <CategoryEntity>, IEnumerable <CategoryViewModel> >(categoryEntities);
                    return(categories);
                }
            }
            return(null);
        }
Пример #5
0
        public async Task <JsonResult> GetCategories()
        {
            try
            {
                int companyId = Convert.ToInt32(HttpContext.User.Claims.First(c => c.Type == "CompanyId").Value);
                var list      = await categoryServices.GetAllCategories(companyId);

                return(Json(list));
            }
            catch (Exception ex)
            {
                await errorServices.ErrorNotification(ex, HttpContext.User.Identity.Name, "", "");

                return(Json(ex));
            }
        }
 public IEnumerable <CategoryInfo> GetAllCategories()
 {
     return(_services.GetAllCategories());
 }
 public List <Category> GetAllCategories()
 {
     return(categoryServices.GetAllCategories());
 }