public int Insert(MemberFoodDiaryMealAddRequest model)
        {
            try
            {
                int id = 0;
                _baseService.DataProvider.ExecuteNonQuery(_baseService.GetConnection, "dbo.MemberFoodDiaryMeal_Insert", inputParamMapper : delegate(SqlParameterCollection paramCollection)
                {
                    paramCollection.AddWithValue("@FoodDiaryMealTypeId", model.FoodDiaryMealTypeId);
                    paramCollection.AddWithValue("@MealDescription", model.MealDescription);
                    paramCollection.AddWithValue("@Calories", model.Calories);
                    paramCollection.AddWithValue("@Carbs", model.Carbs);
                    paramCollection.AddWithValue("@Protein", model.Protein);
                    paramCollection.AddWithValue("@MemberProfileId", model.MemberProfileId);

                    SqlParameter p = new SqlParameter("@Id", System.Data.SqlDbType.Int);
                    p.Direction    = System.Data.ParameterDirection.Output;

                    paramCollection.Add(p);
                }, returnParameters : delegate(SqlParameterCollection param)
                {
                    int.TryParse(param["@Id"].Value.ToString(), out id);
                });
                return(id);
            }
            catch (Exception ex)
            {
                _baseService.LogError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex, "MemberFoodDiaryMealService");
                throw;
            }
        }
Esempio n. 2
0
        public HttpResponseMessage Insert(MemberFoodDiaryMealAddRequest model)
        {
            model.MemberProfileId = _memberProfileService.GetCurrentMemberProfile().Id;
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadGateway, string.Join(", ", ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage))));
            }
            SuccessResponse response = new SuccessResponse();

            try
            {
                _memberFoodDiaryMealService.Insert(model);
                return(Request.CreateResponse(HttpStatusCode.OK, response));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }