Beispiel #1
0
        public IActionResult CreateCategory(FoodCategoryClient reqObj)
        {
            if (reqObj == null)
            {
                BadRequest();
            }

            JSONRetObj <int?> retObj = new JSONRetObj <int?>();

            try
            {
                retObj.IsSuccess = true;
                retObj.Message   = "";
                FoodCategory    foodCategory    = Mapper.Map <FoodCategory>(reqObj);
                FoodCategoryDTO foodCategoryDto = Mapper.Map <FoodCategoryDTO>(foodCategory);
                int             foodMarkerId    = _repoFoodCategory.Post(foodCategoryDto);
                retObj.ResponseObj = foodMarkerId;
            }
            catch (Exception ex)
            {
                retObj.IsSuccess   = false;
                retObj.Message     = ex.Message;
                retObj.ResponseObj = null;
            }

            ViewData["RetObj"] = retObj;

            return(View("_Success"));
        }
        public int Post([FromBody] FoodCategoryClient reqObj)
        {
            if (reqObj == null)
            {
                BadRequest();
            }

            FoodCategory foodCategory = _mapper.Map <FoodCategory>(reqObj);

            return(_service.PostFoodCategory(foodCategory));
        }
        public IEnumerable <FoodCategoryClient> Get()
        {
            List <FoodCategoryClient> retLst = new List <FoodCategoryClient>();

            var categories = _service.GetFoodCategories();

            foreach (var cat in categories)
            {
                FoodCategoryClient foodCategoryRet = _mapper.Map <FoodCategoryClient>(cat);
                retLst.Add(foodCategoryRet);
            }

            return(retLst);
        }