public IHttpActionResult Get(string id)
        {
            string       orderId = id.ToString();
            Klarna_Order order   = db.Klarna_Orders.SingleOrDefault(o => o.OrderNo_ == id);

            if (order == null)
            {
                return(NotFound());
            }
            return(Ok(order));
        }
        public IHttpActionResult PostOrder(string id, [FromBody] Klarna_Order order)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!id.Equals(order.KlarnaID))
            {
                return(BadRequest());
            }

            if (order.Status_Payment == 1)
            {
                order.Status_Payment_Text = order.Status_Payment_Text + " " + DateTime.Now;
            }
            db.Entry(order).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                LogHandler.LogException(e);
                //EventLog eventLog = new EventLog("Application");
                //eventLog.Source = "Application";
                //eventLog.WriteEntry("Log message 1", EventLogEntryType.Information, 101, 1);
                //foreach (var eve in e.EntityValidationErrors)
                //{
                //    eventLog.WriteEntry("Log message 2", EventLogEntryType.Information, 101, 1);
                //    foreach (var ve in eve.ValidationErrors)
                //    {
                //        eventLog.WriteEntry("Property: " + ve.PropertyName + " - " + "Error: " + ve.ErrorMessage, EventLogEntryType.Information, 101, 1);
                //    }
                //}
                return(NotFound());
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(order.OrderNo_))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(StatusCode(HttpStatusCode.OK));
        }
예제 #3
0
 public IHttpActionResult UpdatePayment(string id)
 {
     if (!CustomerExists(id))
     {
         return(NotFound());
     }
     else
     {
         Klarna_Order order = db.Klarna_Orders.SingleOrDefault(o => o.KlarnaID == id);
         if (order == null)
         {
             return(NotFound());
         }
         else
         {
             order.Status_Payment      = 1;
             order.Status_Payment_Text = Constants.PAYMENT_COMPLETED + " " + DateTime.Now;
             db.Entry(order).State     = EntityState.Modified;
             try
             {
                 db.SaveChanges();
             }
             catch (DbEntityValidationException e)
             {
                 LogHandler.LogException(e);
                 return(NotFound());
             }
             catch (DbUpdateConcurrencyException)
             {
                 if (!CustomerExists(id))
                 {
                     return(NotFound());
                 }
                 else
                 {
                     throw;
                 }
             }
             return(StatusCode(HttpStatusCode.OK));
         }
     }
 }