public IHttpActionResult DeletePurchaseOrder(int id)
 {
     DAL.PurchaseOrder order = new DAL.PurchaseOrder();
     order          = Entities.PurchaseOrders.Where(s => s.ID == id).FirstOrDefault();
     order.IsActive = false;
     Entities.SaveChanges();
     return(Ok(true));
 }
        public IHttpActionResult UpdatePurchaseOrder(PurchaseOrder order)
        {
            var    list     = new List <PurchaseOrder>();
            var    pageName = Request.RequestUri.LocalPath.getRouteName();
            Object obj      = null;
            var    UserId   = 0;

            if (Request.Headers.Contains("Email"))
            {
                var email = ((string[])(Request.Headers.GetValues("Email")))[0].ToString();
                UserId = Entities.Users.Where(x => x.IsActive == true && x.Email.Contains(email)).FirstOrDefault().Id;
            }
            string logTable = "";

            DAL.PurchaseOrder Orders = new DAL.PurchaseOrder();
            Orders                       = Entities.PurchaseOrders.Where(s => s.ID == order.ID).FirstOrDefault();
            Orders.OrderNumber           = order.OrderNumber;
            Orders.ClientInvoiceNumber   = order.ClientInvoiceNumber;
            Orders.SupplierId            = order.SupplierId;
            Orders.BuyerId               = order.BuyerId;
            Orders.OrderDate             = order.OrderDate;
            Orders.ExpectedDeliveryDate  = order.ExpectedDeliveryDate;
            Orders.FirstDeliveryDate     = order.FirstDeliveryDate;
            Orders.OrderCompletionDate   = order.OrderCompletionDate;
            Orders.Quantity              = order.Quantity;
            Orders.Amount                = order.Amount ?? 0;
            Orders.VatAmount             = order.VatAmount;
            Orders.PurchaseOrderStatusId = order.PurchaseOrderStatusId;
            Orders.IsActive              = true;
            try
            {
                Entities.SaveChanges();
                list.Add(Orders);
                return(Ok(true));
            }
            catch (DbUpdateConcurrencyException ex)
            {
                obj = ex;
            }

            finally
            {
                if (obj == null)
                {
                    logTable = "";
                    var change = list.ToDataTables().getChangedRecords();
                    var c      = change.Count() / 2;
                    for (var i = 0; i < c; i++)
                    {
                        logTable += change[i].Fieldname + " Old Value=[" + change[i].FieldValue + "] New Value=[" + change[i + c].FieldValue + "], ";
                    }
                    //logTable = Newtonsoft.Json.JsonConvert.SerializeObject(change);
                    var flag = order.CreateLog(pageName, logTable, UserId);
                }
            }
            return(Ok(true));
        }
        public IHttpActionResult AddPurchaseOrder(PurchaseOrder order)
        {
            var    pageName = Request.RequestUri.LocalPath.getRouteName();
            Object obj      = null;
            var    UserId   = 0;

            if (Request.Headers.Contains("Email"))
            {
                var email = ((string[])(Request.Headers.GetValues("Email")))[0].ToString();
                UserId = Entities.Users.Where(x => x.IsActive == true && x.Email.Contains(email)).FirstOrDefault().Id;
            }
            DAL.PurchaseOrder Orders = new DAL.PurchaseOrder();
            Orders.OrderNumber          = order.OrderNumber;
            Orders.ClientInvoiceNumber  = order.ClientInvoiceNumber;
            Orders.SupplierId           = order.SupplierId;
            Orders.BuyerId              = order.BuyerId;
            Orders.OrderDate            = order.OrderDate;
            Orders.ExpectedDeliveryDate = order.ExpectedDeliveryDate;
            Orders.FirstDeliveryDate    = order.FirstDeliveryDate;
            Orders.OrderCompletionDate  = order.OrderCompletionDate;
            Orders.Quantity             = 0;
            Orders.Amount                = 0;
            Orders.VatAmount             = order.VatAmount;
            Orders.PurchaseOrderStatusId = order.PurchaseOrderStatusId;
            Orders.IsActive              = true;
            Entities.PurchaseOrders.Add(Orders);
            try
            {
                Entities.SaveChanges();
            }
            catch (Exception ex) { obj = ex; }
            finally
            {
                if (obj == null)
                {
                    var logTable = Newtonsoft.Json.JsonConvert.SerializeObject(Orders, new JsonSerializerSettings()
                    {
                        PreserveReferencesHandling = PreserveReferencesHandling.Objects,
                        Formatting = Formatting.Indented
                    });
                    var flag = Orders.CreateLog(pageName, logTable, UserId);
                }
            }
            int id = Orders.ID;

            return(Ok(id));
        }
Esempio n. 4
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            var shop1 = new Shop
            {
                Id = 1, Name = "ATB"
            };
            var shop2 = new Shop
            {
                Id = 2, Name = "Rozetka"
            };

            var warehouse1 = new Warehouse
            {
                Id = 1, Name = "First warehouse"
            };
            var warehouse2 = new Warehouse
            {
                Id = 2, Name = "Second warehouse"
            };

            var commodity1 = new Commodity
            {
                Id = 1, Name = "Bread", Price = 20
            };
            var commodity2 = new Commodity
            {
                Id = 2, Name = "Wine", Price = 150
            };

            var commInShop1 = new CommodityInShop
            {
                Id = 1, CommodityId = 1, ShopId = 1
            };
            var commInShop2 = new CommodityInShop
            {
                Id = 2, CommodityId = 2, ShopId = 2
            };

            var commInWarehouse1 = new CommodityInWarehouse
            {
                Id = 1, CommodityId = 2, WarehouseId = 1
            };
            var commInWarehouse2 = new CommodityInWarehouse
            {
                Id = 2, CommodityId = 1, WarehouseId = 2
            };

            var order1 = new PurchaseOrder
            {
                Id = 1, Date = DateTime.Now, ShopId = 1, Name = "Sample order", Number = 1001
            };
            var order2 = new PurchaseOrder
            {
                Id = 2, Date = DateTime.Now, ShopId = 2, Name = "Second sample order", Number = 10011001
            };

            var ordComm1 = new OrdersCommodities
            {
                Id = 1, CommodityId = 1, PurchaseOrderId = 1
            };
            var ordComm2 = new OrdersCommodities
            {
                Id = 2, CommodityId = 2, PurchaseOrderId = 1
            };
            var ordComm3 = new OrdersCommodities
            {
                Id = 3, CommodityId = 1, PurchaseOrderId = 2
            };
            var ordComm4 = new OrdersCommodities
            {
                Id = 4, CommodityId = 2, PurchaseOrderId = 2
            };

            modelBuilder.Entity <Shop>().HasData(shop1, shop2);
            modelBuilder.Entity <Warehouse>().HasData(warehouse1, warehouse2);
            modelBuilder.Entity <PurchaseOrder>().HasData(order1, order2);
            modelBuilder.Entity <Commodity>().HasData(commodity1, commodity2);
            modelBuilder.Entity <CommodityInShop>().HasData(commInShop1, commInShop2);
            modelBuilder.Entity <CommodityInWarehouse>().HasData(commInWarehouse1, commInWarehouse2);
            modelBuilder.Entity <OrdersCommodities>().HasData(ordComm1, ordComm2, ordComm3, ordComm4);
        }