Ejemplo n.º 1
0
        public ActionResult Notification(MercadoPagoNotification not)
        {
            string data_id = Request.QueryString["data.id"];

            if (not.data != null)
            {
                data_id = not.data.id;
            }

            DateTime date_created = DateTime.Now;

            DateTime.TryParse(not.date_created, out date_created);

            bool live_mode = false;

            bool.TryParse(not.live_mode, out live_mode);

            MercadoPagoNotificationModel model = new MercadoPagoNotificationModel()
            {
                action = not.action, api_version = not.api_version, data_id = data_id, date_created = date_created.Date, obj_id = not.id, live_mode = live_mode, type = not.type, user_id = not.user_id, data_content = JsonConvert.SerializeObject(not)
            };

            MercadoPagoNotificationService.SaveNotification(model);

            return(new HttpStatusCodeResult(HttpStatusCode.Created));
        }
        public static void SaveNotification(MercadoPagoNotificationModel model)
        {
            using (ctaDBEntities entities = new ctaDBEntities())
            {
                entities.MercadoPagoNotifications.Add(new MercadoPagoNotification()
                {
                    action = model.action, api_version = model.api_version, data_content = model.data_content, data_id = model.data_id, date_created = model.date_created, live_mode = model.live_mode, obj_id = model.obj_id, type = model.type, user_id = model.user_id
                });
                entities.SaveChanges();

                if (!(entities.Database.Connection.State == ConnectionState.Closed))
                {
                    entities.Database.Connection.Close();
                }
            }
        }