Example #1
0
        public Order_DataAccessLayer.Model.Order GetOrderByID(int?id)
        {
            try
            {
                Order_DataAccessLayer.Model.Order entity = _context.Orders.FirstOrDefault(x => x.OrderId == id);
                if (entity != null)
                {
                    _context.Orders.Find(id);
                }
                else
                {
                    throw new Exception("Order not found");
                }
                return(entity);
            }

            catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
            {
                Exception raise = dbEx;
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        string message = string.Format("{0}:{1}",
                                                       validationErrors.Entry.Entity.ToString(),
                                                       validationError.ErrorMessage);
                        raise = new InvalidOperationException(message, raise);
                    }
                }
                throw raise;
            }
        }
Example #2
0
 public void UpdateOrder(Order_DataAccessLayer.Model.Order order)
 {
     try
     {
         _context.Entry(order).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
         Commit();
     }
     catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
     {
         Exception raise = dbEx;
         foreach (var validationErrors in dbEx.EntityValidationErrors)
         {
             foreach (var validationError in validationErrors.ValidationErrors)
             {
                 string message = string.Format("{0}:{1}",
                                                validationErrors.Entry.Entity.ToString(),
                                                validationError.ErrorMessage);
                 raise = new InvalidOperationException(message, raise);
             }
         }
         throw raise;
     }
 }
Example #3
0
 public Order_DataAccessLayer.Model.Order AddOrder(Order_DataAccessLayer.Model.Order order)
 {
     try
     {
         _context.Orders.Add(order);
         Commit();
         return(order);
     }
     catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
     {
         Exception raise = dbEx;
         foreach (var validationErrors in dbEx.EntityValidationErrors)
         {
             foreach (var validationError in validationErrors.ValidationErrors)
             {
                 string message = string.Format("{0}:{1}",
                                                validationErrors.Entry.Entity.ToString(),
                                                validationError.ErrorMessage);
                 raise = new InvalidOperationException(message, raise);
             }
         }
         throw raise;
     }
 }