コード例 #1
0
        /// <summary>
        /// Add new product/ service category
        /// </summary>
        /// <param name="category"></param>
        /// <returns></returns>
        public Guid AddNewCategory(CATEGORy category)
        {
            try
            {
                if(category == null)
                    throw new ArgumentNullException("Category", "Category can not be null");

                // check if all required fields are present
                if(category.NAME == null || !category.SERVICE.HasValue)
                    throw new ArgumentException("Category", "Some mandatory parameters required to add a new category are missing");

                if (!category.ID.HasValue || category.ID.Value == Guid.Empty)
                    category.ID = Guid.NewGuid();

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        db.CATEGORIES.Add(category);
                        db.SaveChanges();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                }

                return category.ID.Value;
            }
            catch (Exception e)
            {
                throw;
            }

        }
コード例 #2
0
 public HttpResponseMessage AddNewCategory(CATEGORy category)
 {
     try
     {
         var commonService = new CommonService();
         var id = commonService.AddNewCategory(category);
         var response = Request.CreateResponse(HttpStatusCode.OK, id);
         return response;
     }
     catch (Exception e)
     {
         var error = Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message);
         return error;
     }
 }