public static CategoryOutputModel MapToCategoryOutputModel(this Category category)
        {
            var model = new CategoryOutputModel
            {
                Name          = category.Name,
                Currency      = category.Currency.ToString(),
                PlannedAmount = category.PlannedAmount,
                Balance       = category.Balance,
                Id            = category.Id,
                SubCategories = category.SubCategories.Select(x => x.MapToCategoryOutputModel())
            };

            return(model);
        }
        public CategoryServiceTest()
        {
            //Models
            category = new Category {
                Id = Guid.NewGuid(), Description = "Refrigerante"
            };
            categoryInput = new CategoryInputModel {
                Description = "Refrigerante"
            };
            categoryOutput = new CategoryOutputModel {
                Id = Guid.NewGuid(), Description = "Refrigerante"
            };

            //Mocks
            mockCategoryRepository = new Mock <ICategoryRepository>();
            mockMapper             = new Mock <IMapper>();
        }
        public IHttpActionResult Post(CategoryOutputModel categoryModel)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest("The model is invalid");
            }

            Category category = new Category();

            category.Name = categoryModel.Name;

            this.data.Categories.Add(category);
            this.data.SaveChanges();

            return this.Ok(new CategoryOutputModel()
            {
                Id = category.Id,
                Name = category.Name
            });
        }
Exemplo n.º 4
0
        public IActionResult GetHaragCategoriesAjax()
        {
            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                return(Unauthorized());
            }

            if (!_workContext.CurrentCustomer.IsInCustomerRole(RolesType.Administrators, true) && !_workContext.CurrentCustomer.IsInCustomerRole(RolesType.HaragAdmin, true))
            {
                return(Forbid());
            }

            //Server Side Parameters
            var start = Convert.ToInt32(Request.Form["start"].FirstOrDefault());

            int    length         = Convert.ToInt32(Request.Form["length"]);
            string searchValue    = Request.Form["search[value]"];
            string sortColumnName = Request.Form["columns[" + Request.Form["order[0][column]"] + "][name]"];
            string sortDirection  = Request.Form["order[0][dir]"];

            var categoriesInDb = _categoryService.GetCategories(start, length, searchValue, sortColumnName, sortDirection);

            var categories = new CategoryOutputModel
            {
                Items = categoriesInDb.Select(c => new CategoryModel
                {
                    Id          = c.Id,
                    Name        = c.Name,
                    Description = c.Description,
                    IsActive    = c.IsActive
                }).ToList()
            };


            return(Json(new { data = categories.Items }));
        }
        public IHttpActionResult Put(int id, CategoryOutputModel categoryModel)
        {
            Category category = this.data.Categories.GetById(id);

            if (category == null)
            {
                return this.BadRequest("The specified category id is invalid");
            }

            if (categoryModel.Name == null)
            {
                return this.BadRequest("The category name cannot be left empty");
            }

            category.Name = categoryModel.Name;

            this.data.SaveChanges();

            return this.Ok();
        }