Esempio n. 1
0
        private void PopulateModel(MerchantBookingType model, IDictionary values)
        {
            string ID = nameof(MerchantBookingType.id);
            string MERCHANT_DETAILS_ID = nameof(MerchantBookingType.merchant_details_id);
            string BOOKING_TYPE        = nameof(MerchantBookingType.booking_type);
            string VALUE      = nameof(MerchantBookingType.value);
            string CREATED_AT = nameof(MerchantBookingType.created_at);
            string UPDATED_AT = nameof(MerchantBookingType.updated_at);
            string STATE      = nameof(MerchantBookingType.state);

            if (values.Contains(ID))
            {
                model.id = Convert.ToInt32(values[ID]);
            }

            if (values.Contains(MERCHANT_DETAILS_ID))
            {
                model.merchant_details_id = Convert.ToString(values[MERCHANT_DETAILS_ID]);
            }

            if (values.Contains(BOOKING_TYPE))
            {
                model.booking_type = Convert.ToString(values[BOOKING_TYPE]);
            }

            if (values.Contains(VALUE))
            {
                model.value = Convert.ToString(values[VALUE]);
            }

            if (values.Contains(CREATED_AT))
            {
                model.created_at = Convert.ToDateTime(values[CREATED_AT]);
            }

            if (values.Contains(UPDATED_AT))
            {
                model.updated_at = Convert.ToDateTime(values[UPDATED_AT]);
            }

            if (values.Contains(STATE))
            {
                model.state = Convert.ToString(values[STATE]);
            }
        }
Esempio n. 2
0
        public HttpResponseMessage Post(FormDataCollection form)
        {
            var model  = new MerchantBookingType();
            var values = JsonConvert.DeserializeObject <IDictionary>(form.Get("values"));

            PopulateModel(model, values);

            Validate(model);
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, GetFullErrorMessage(ModelState)));
            }

            var result = _context.MerchantBookingTypes.Add(model);

            _context.SaveChanges();

            return(Request.CreateResponse(HttpStatusCode.Created, result.id));
        }