Beispiel #1
0
 public void UpdateOrder(int order, string products, string quantities)
 {
     using (Models.UserTableEntities1 db = new Models.UserTableEntities1())
     {
         //var company = db.Tables.FirstOrDefault(x => x.Username == User.Identity.Name).CompanyName;
         var company  = "Edited by: " + User.Identity.Name + " original order ID is: " + order;
         var newOrder = new Order {
             Comapny = company, Pending = "Pending"
         };
         var productArray  = products.Split(',');
         var quantityArray = quantities.Split(',');
         db.Orders.Add(newOrder);
         db.SaveChanges();
         db.AdminOrders.Add(new AdminOrder {
             AdminOrder_Id = newOrder.Id, Order_Id = order
         });
         db.SaveChanges();
         for (var i = 0; i < productArray.Length; i++)
         {
             var newOrderProduct = new OrderProduct {
                 Order_Id = newOrder.Id, Product_Id = Convert.ToInt32(productArray[i]), Quantity = Convert.ToInt32(quantityArray[i])
             };
             db.OrderProducts.Add(newOrderProduct);
             db.SaveChanges();
         }
     }
 }
Beispiel #2
0
        public ActionResult ManageAccount(AGIMaster.Models.Table EditAccount)
        {
            AGIMaster.Models.Table userInfo = new AGIMaster.Models.Table();
            using (Models.UserTableEntities1 db = new Models.UserTableEntities1())
            {
                userInfo = db.Tables.FirstOrDefault(x => x.Username == User.Identity.Name);
            }

            userInfo.CompanyAddress        = EditAccount.CompanyAddress;
            userInfo.PrimaryContactName    = EditAccount.PrimaryContactName;
            userInfo.PrimaryEmailAddress   = EditAccount.PrimaryEmailAddress;
            userInfo.PrimaryPhone          = EditAccount.PrimaryPhone;
            userInfo.SecondaryContactName  = EditAccount.SecondaryContactName;
            userInfo.SecondaryEmailAddress = EditAccount.SecondaryEmailAddress;
            userInfo.SecondaryPhone        = EditAccount.SecondaryPhone;
            userInfo.ShippingAddress       = EditAccount.ShippingAddress;
            userInfo.ConfirmPassword       = userInfo.Password;

            using (Models.UserTableEntities1 db = new Models.UserTableEntities1())
            {
                db.Entry(userInfo).State = EntityState.Modified;
                try
                {
                    db.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    foreach (DbEntityValidationResult item in ex.EntityValidationErrors)
                    {
                        // Get entry

                        DbEntityEntry entry          = item.Entry;
                        string        entityTypeName = entry.Entity.GetType().Name;

                        // Display or log error messages

                        foreach (DbValidationError subItem in item.ValidationErrors)
                        {
                            string message = string.Format("Error '{0}' occurred in {1} at {2}",
                                                           subItem.ErrorMessage, entityTypeName, subItem.PropertyName);
                            Console.WriteLine(message);
                        }
                    }
                }
            }
            return(View());
        }