Exemplo n.º 1
0
        public static void SaveInvoice(InvoiceModel invoiceModel)
        {
            if (UserHelper.UserID != null)
            {
                var storageDbEntities = new StorageDBEntities();

                Invoice invoice = new Invoice
                {
                    SupplierID  = invoiceModel.Supplier.ID,
                    RecipientID = invoiceModel.Recipient.ID,
                    Date        = invoiceModel.Date,
                    Type        = invoiceModel.Type,
                    Number      = invoiceModel.Number,
                    PriceType   = invoiceModel.PriceType,
                    UserID      = UserHelper.UserID.Value
                };

                foreach (ProductsInInvoiceModel productsInInvoiceModel in invoiceModel.Products.Where(p => p.ProductID > 0).ToList())
                {
                    ProductsInInvoice productsInInvoice = new ProductsInInvoice
                    {
                        Price     = productsInInvoiceModel.Price,
                        Quantity  = productsInInvoiceModel.Quantity,
                        ProductID = productsInInvoiceModel.ProductID
                    };

                    invoice.ProductsInInvoices.Add(productsInInvoice);
                }

                storageDbEntities.Invoices.AddObject(invoice);

                storageDbEntities.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public static void DeleteInvoice(int id)
        {
            var storageDbEntities = new StorageDBEntities();

            Invoice invoice = storageDbEntities.Invoices.Where(inv => inv.ID == id && inv.UserID == UserHelper.UserID).FirstOrDefault();

            if (invoice != null)
            {
                foreach (ProductsInInvoice productsInInvoice in invoice.ProductsInInvoices.ToList())
                {
                    storageDbEntities.ProductsInInvoices.DeleteObject(productsInInvoice);
                    storageDbEntities.SaveChanges();
                }

                storageDbEntities.Invoices.DeleteObject(invoice);
                storageDbEntities.SaveChanges();
            }
        }
Exemplo n.º 3
0
        public static void DeleteClient(int id)
        {
            var storageDbEntities = new StorageDBEntities();

            Client client = storageDbEntities.Clients.Where(c => c.ID == id && c.UserID == UserHelper.UserID).FirstOrDefault();

            storageDbEntities.Clients.DeleteObject(client);

            storageDbEntities.SaveChanges();
        }
Exemplo n.º 4
0
        public static void DeleteProduct(int id)
        {
            var storageDbEntities = new StorageDBEntities();

            Category category = storageDbEntities.Categories.Where(p => p.ID == id && p.UserID == UserHelper.UserID).FirstOrDefault();

            storageDbEntities.Categories.DeleteObject(category);

            storageDbEntities.SaveChanges();
        }
Exemplo n.º 5
0
        public static void UpdateProduct(int id, CategoryModel categoryModel)
        {
            var storageDbEntities = new StorageDBEntities();

            Category category = storageDbEntities.Categories.Where(c => c.ID == id && c.UserID == UserHelper.UserID).FirstOrDefault();

            if (category != null)
            {
                category.Name = categoryModel.Name;
            }

            storageDbEntities.SaveChanges();
        }
Exemplo n.º 6
0
        public static void UpdateUser(UserModel userModel)
        {
            var storageDbEntities = new StorageDBEntities();

            User user = storageDbEntities.Users.Where(u => u.ID == userModel.ID).FirstOrDefault();

            if (user != null)
            {
                user.Name    = userModel.Name;
                user.Surname = userModel.Surname;
            }

            storageDbEntities.SaveChanges();
        }
Exemplo n.º 7
0
        public static void UpdateClient(int id, ClientModel clientModel)
        {
            var storageDbEntities = new StorageDBEntities();

            Client client = storageDbEntities.Clients.Where(c => c.ID == id && c.UserID == UserHelper.UserID).FirstOrDefault();

            if (client != null)
            {
                client.Name      = clientModel.Name;
                client.Address   = clientModel.Address;
                client.Telephone = clientModel.Telephone;
            }

            storageDbEntities.SaveChanges();
        }
Exemplo n.º 8
0
        public static void UpdateInvoice(InvoiceModel invoiceModel)
        {
            var storageDbEntities = new StorageDBEntities();

            Invoice invoice = storageDbEntities.Invoices.Where(inv => inv.ID == invoiceModel.ID && inv.UserID == UserHelper.UserID).FirstOrDefault();

            if (invoice != null)
            {
                // updates invoice metadata
                invoice.SupplierID  = invoiceModel.Supplier.ID;
                invoice.RecipientID = invoiceModel.Recipient.ID;
                invoice.PriceType   = invoiceModel.PriceType;

                foreach (var productInInvoice in invoice.ProductsInInvoices.ToList())
                {
                    ProductsInInvoiceModel productsInInvoiceModel = invoiceModel.Products.Where(p => p.ProductID == productInInvoice.ProductID).FirstOrDefault();

                    // product was updated by user
                    if (productsInInvoiceModel != null)
                    {
                        productInInvoice.Price    = productsInInvoiceModel.Price;
                        productInInvoice.Quantity = productsInInvoiceModel.Quantity;

                        invoiceModel.Products.Remove(productsInInvoiceModel);
                    }
                    // product was deleted by user
                    else
                    {
                        storageDbEntities.ProductsInInvoices.DeleteObject(productInInvoice);
                    }
                }

                // products were created by user
                foreach (var productsInInvoiceModel in invoiceModel.Products.Where(p => p.ProductID > 0).ToList())
                {
                    ProductsInInvoice productsInInvoice = new ProductsInInvoice
                    {
                        Price     = productsInInvoiceModel.Price,
                        Quantity  = productsInInvoiceModel.Quantity,
                        ProductID = productsInInvoiceModel.ProductID
                    };

                    invoice.ProductsInInvoices.Add(productsInInvoice);
                }

                storageDbEntities.SaveChanges();
            }
        }
Exemplo n.º 9
0
        public static void CreateProduct(CategoryModel categoryModel)
        {
            if (UserHelper.UserID != null)
            {
                var storageDbEntities = new StorageDBEntities();

                Category newCategory = new Category
                {
                    Name   = categoryModel.Name,
                    UserID = UserHelper.UserID.Value
                };

                storageDbEntities.Categories.AddObject(newCategory);

                storageDbEntities.SaveChanges();
            }
        }
Exemplo n.º 10
0
        public static void CreateClient(ClientModel clientModel)
        {
            if (UserHelper.UserID != null)
            {
                var storageDbEntities = new StorageDBEntities();

                Client newClient = new Client
                {
                    Name      = clientModel.Name,
                    Address   = clientModel.Address,
                    Telephone = clientModel.Telephone,
                    UserID    = UserHelper.UserID.Value
                };

                storageDbEntities.Clients.AddObject(newClient);

                storageDbEntities.SaveChanges();
            }
        }
Exemplo n.º 11
0
        public static void UpdateProduct(int id, ProductModel productModel)
        {
            var storageDbEntities = new StorageDBEntities();

            Product product = storageDbEntities.Products.Where(p => p.ID == id && p.UserID == UserHelper.UserID).FirstOrDefault();

            if (product != null)
            {
                product.Code                  = productModel.Code;
                product.Name                  = productModel.Name;
                product.Unit                  = productModel.Unit;
                product.WholesalePrice        = productModel.WholesalePrice;
                product.ShallowWholesalePrice = productModel.ShallowWholesalePrice;
                product.RetailPrice           = productModel.RetailPrice;
                product.CategoryID            = productModel.Category.ID;
            }

            storageDbEntities.SaveChanges();
        }
Exemplo n.º 12
0
        public static void CreateProduct(ProductModel productModel)
        {
            if (UserHelper.UserID != null)
            {
                var storageDbEntities = new StorageDBEntities();

                Product newProduct = new Product
                {
                    Code                  = productModel.Code,
                    Name                  = productModel.Name,
                    Unit                  = productModel.Unit,
                    WholesalePrice        = productModel.WholesalePrice,
                    ShallowWholesalePrice = productModel.ShallowWholesalePrice,
                    RetailPrice           = productModel.RetailPrice,
                    CategoryID            = productModel.Category.ID,
                    UserID                = UserHelper.UserID.Value
                };

                storageDbEntities.Products.AddObject(newProduct);

                storageDbEntities.SaveChanges();
            }
        }