Пример #1
0
        public HttpResponseMessage PostEvent(FormDataCollection formCollection)
        {
            var model = new SocketLabsEvent(formCollection);

            // check that serverId and secret key match
            if (_config.ContainsKey(model.ServerId))
            {
                var config = _config[model.ServerId];
                if (config.Key == model.SecretKey)
                {
                    // basic example of using the different types to do different actions
                    switch (model.Type)
                    {
                    case EventType.Validation:
                        break;     // we shouldn't save this, just return the key as per the API requirements

                    case EventType.Delivered:
                        DeliveryEvents.Add(model);
                        // you might save this in a separate database table or repository from the others
                        break;

                    case EventType.Complaint:
                        DeliveryEvents.Add(model);
                        // you might save this in a separate database table or repository from the others
                        break;

                    case EventType.Failed:
                        DeliveryEvents.Add(model);
                        // you might save this in a separate database table or repository from the others
                        break;

                    case EventType.Tracking:
                        TrackingEvents.Add(model);
                        // you might save this in a separate database table or repository from the others
                        break;

                    default:
                        UnknownEvents.Add(model);
                        // you might save this in a separate database table or repository from the others
                        break;
                    }

                    // the Validation Key...  not returning this will prevent proper function of your endpoint
                    return(Request.CreateResponse(HttpStatusCode.OK, config.Value));
                }
            }
            return(Request.CreateResponse(HttpStatusCode.Unauthorized, "Secret Key validation failed!"));
        }
        public ActionResult PostEvent(FormCollection formCollection)
        {
            var model = new SocketLabsEvent(formCollection);

            // check that serverId and secret key match
            if (_config.ContainsKey(model.ServerId))
            {
                var config = _config[model.ServerId];
                if (config.Key == model.SecretKey)
                {
                    // basic example of using the different types to do different actions
                    switch (model.Type)
                    {
                    case EventType.Validation:
                        break;     // we shouldn't save this, just return the key as per the API requirements

                    case EventType.Delivered:
                        _storedEvents.Add(model);
                        // you might save this in a separate database table or repository from the others
                        break;

                    case EventType.Complaint:
                        _storedEvents.Add(model);
                        // you might save this in a separate database table or repository from the others
                        break;

                    case EventType.Failed:
                        _storedEvents.Add(model);
                        // you might save this in a separate database table or repository from the others
                        break;
                    }

                    return(Content(config.Value)); // the Validation Key...  not returning this will prevent proper function of your endpoint
                }
            }

            return(new HttpUnauthorizedResult()); // ServerId vs SecretKey validation failed
        }