public ActionResult AddCookType(CreateCookTypeRequest createCookType)
        {
            if (!_validator.Validate(createCookType))
            {
                return(BadRequest(new { error = "invalid cook type" }));
            }
            var newCookType = _cookTypeRepository.AddCookType(createCookType);

            return(Created($"api/cookTypes/{newCookType.Id}", newCookType));
        }
        public CookType AddCookType(CreateCookTypeRequest newCookTypeObj)
        {
            using (var db = new SqlConnection(ConnectionString))
            {
                var newCookTypeQuery = db.QueryFirstOrDefault <CookType>(@"
                                                                        Insert into CookType (userId, categoryId)
                                                                        Output inserted.*
                                                                        Values(@userId,@categoryId)",
                                                                         new
                {
                    newCookTypeObj.UserId,
                    newCookTypeObj.CategoryId
                });
                if (newCookTypeQuery != null)
                {
                    return(newCookTypeQuery);
                }

                throw new Exception("No Cook Type Found");
            }
        }
 public bool Validate(CreateCookTypeRequest requestToValidate)
 {
     return(!(string.IsNullOrEmpty(requestToValidate.UserId.ToString()) ||
              string.IsNullOrEmpty(requestToValidate.CategoryId.ToString())));
 }