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); } }
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); }
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); } }