Beispiel #1
0
 public bool Create(CategoryViewModel category)
 {
     try
     {
         Category cat = new Category
         {
             Name        = category.Name,
             Description = category.Description
         };
         db.Categories.Add(cat);
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Beispiel #2
0
        public bool CompleteOrder(Guid shippingId, Cart cart, string userId)
        {
            Order order = new Order();

            order.ShippingID = shippingId;
            order.UserID     = userId;
            order.Total      = cart.ComputeTotalValue();
            db.Orders.Add(order);

            foreach (var prod in cart.Lines)
            {
                OrderProducts prodline = new OrderProducts();
                prodline.OrderID   = order.OrderID;
                prodline.Quantity  = prod.Quantity;
                prodline.ProductID = prod.Product.ProductID;
                db.OrderProducts.Add(prodline);
            }

            db.SaveChanges();
            return(true);
        }
Beispiel #3
0
        public bool Create(ProductViewModel product, string fileStream)
        {
            try
            {
                Product prod = new Product
                {
                    Artist       = product.Artist,
                    CategoryID   = product.selectedCategoryID,
                    Description  = product.Description,
                    Name         = product.Name,
                    PremiereDate = product.PremiereDate,
                    Price        = product.Price
                };
                if (fileStream != null)
                {
                    var extension = fileStream.Substring(fileStream.IndexOf(':') + 1);
                    var extLength = extension.IndexOf(';');
                    var allLength = extension.Length - extLength;
                    extension = extension.Remove(extLength, allLength);

                    var file = fileStream.Substring(fileStream.IndexOf(',') + 1);

                    var bytes = Convert.FromBase64String(file);
                    prod.PictureMimeType = extension;
                    prod.PictureData     = bytes;
                }

                db.Products.Add(prod);
                db.SaveChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }