Ejemplo n.º 1
0
        public async Task <ActionResult <PurchaseRequisition> > PostPurchaseRequisition(PurchaseRequisitionDTO purchaseRequisitionDTO)
        {
            SiteManager siteManager = _context.SiteManagers.FirstOrDefault(e => e.StaffId == purchaseRequisitionDTO.SiteManagerId);
            Supplier    supplier    = _context.Supplier.FirstOrDefault(e => e.SupplierCode == purchaseRequisitionDTO.SupplierCode);
            Site        site        = _context.Sites.FirstOrDefault(e => e.SiteCode == purchaseRequisitionDTO.SiteCode);

            PurchaseRequisition purchaseRequisition = new PurchaseRequisition
            {
                ShippingAddress = purchaseRequisitionDTO.ShippingAddress,
                DeliverBefore   = purchaseRequisitionDTO.DeliverBefore,
                DeliveryCost    = purchaseRequisitionDTO.DeliveryCost,
                TotalCost       = purchaseRequisitionDTO.TotalCost,
                Status          = purchaseRequisitionDTO.Status,
                Comments        = purchaseRequisitionDTO.Comments,
                SiteManager     = siteManager,
                Supplier        = supplier,
                Site            = site
            };

            var itemMap = new Dictionary <string, int>();

            foreach (string itemId in purchaseRequisitionDTO.ItemIds)
            {
                if (itemMap.ContainsKey(itemId))
                {
                    itemMap[itemId] = itemMap[itemId] + 1;
                }
                else
                {
                    itemMap.Add(itemId, 1);
                }
            }

            for (int i = 0; i < itemMap.Count; i++)
            {
                var item = new PurchaseRequisitionItems {
                    ItemId = itemMap.ElementAt(i).Key, PurchaseRequisition = purchaseRequisition, ItemCount = itemMap.ElementAt(i).Value
                };

                _context.Set <PurchaseRequisitionItems>().Add(item);
            }

            _context.PurchaseRequisitions.Add(purchaseRequisition);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetPurchaseRequisition", new { id = purchaseRequisition.RequisitionNo }, purchaseRequisition));
        }
Ejemplo n.º 2
0
        private void Seed()
        {
            using (var context = new ProcurementDbContext(ContextOptions))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                var manager1 = new SiteManager {
                    StaffId = "EMP1", FirstName = "FirstName", LastName = "LastName", MobileNo = "0718956874"
                };

                context.SiteManagers.Add(manager1);
                context.SiteManagers.Add(new SiteManager {
                    StaffId = "EMP2", FirstName = "FirstName", LastName = "LastName", MobileNo = "0718956874"
                });
                context.SiteManagers.Add(new SiteManager {
                    StaffId = "EMP3", FirstName = "FirstName", LastName = "LastName", MobileNo = "0718956874"
                });

                context.ManagementStaff.Add(new ManagementStaff {
                    StaffId = "EMP11", FirstName = "FirstName", LastName = "LastName", MobileNo = "0718956874"
                });
                context.ManagementStaff.Add(new ManagementStaff {
                    StaffId = "EMP12", FirstName = "FirstName", LastName = "LastName", MobileNo = "0718956874"
                });
                context.ManagementStaff.Add(new ManagementStaff {
                    StaffId = "EMP13", FirstName = "FirstName", LastName = "LastName", MobileNo = "0718956874"
                });

                context.AccountingStaff.Add(new AccountingStaff {
                    StaffId = "EMP21", FirstName = "FirstName", LastName = "LastName", MobileNo = "0718956874"
                });
                context.AccountingStaff.Add(new AccountingStaff {
                    StaffId = "EMP22", FirstName = "FirstName", LastName = "LastName", MobileNo = "0718956874"
                });
                context.AccountingStaff.Add(new AccountingStaff {
                    StaffId = "EMP23", FirstName = "FirstName", LastName = "LastName", MobileNo = "0718956874"
                });

                var site1 = new Site {
                    SiteCode = "SITE001", SiteName = "SLIIT Campus Site", SiteAddress = "Malabe", Description = "Malabe SLIIT Campus working site", SiteOfficeNo = "0115489657", SiteManager = manager1
                };

                context.Sites.Add(site1);

                var supplier1 = new Supplier {
                    SupplierCode = "SP1", SupplierName = "MAS Holdings", Address1 = "Colombo 3", CompanyNo = "011548795", MobileNo = "077485698", Email = "*****@*****.**"
                };

                context.Supplier.Add(supplier1);
                context.Supplier.Add(new Supplier {
                    SupplierCode = "SP2", SupplierName = "MAS Holdings", Address1 = "Colombo 3", CompanyNo = "011548795", MobileNo = "077485698", Email = "*****@*****.**"
                });
                context.Supplier.Add(new Supplier {
                    SupplierCode = "SP3", SupplierName = "MAS Holdings", Address1 = "Colombo 3", CompanyNo = "011548795", MobileNo = "077485698", Email = "*****@*****.**"
                });

                var item1 = new Item {
                    ItemId = "IT001", ItemName = "Roofing Sheets", ItemPrice = 200.20, Description = "Roof sheets"
                };
                var item2 = new Item {
                    ItemId = "IT002", ItemName = "Roofing Sheets", ItemPrice = 200.20, Description = "Roof sheets"
                };
                var item3 = new Item {
                    ItemId = "IT003", ItemName = "Roofing Sheets", ItemPrice = 200.20, Description = "Roof sheets"
                };
                context.Items.Add(item1);
                context.Items.Add(item2);
                context.Items.Add(item3);
                var itemSupplier1 = new ItemSuppliers {
                    Item = item1, Supplier = supplier1
                };
                var itemSupplier2 = new ItemSuppliers {
                    Item = item2, Supplier = supplier1
                };
                var itemSupplier3 = new ItemSuppliers {
                    Item = item3, Supplier = supplier1
                };
                context.Add(itemSupplier1);
                context.Add(itemSupplier2);
                context.Add(itemSupplier3);

                var requisition1 = new PurchaseRequisition
                {
                    RequisitionNo   = 1,
                    ShippingAddress = "Malabe",
                    TotalCost       = 2000.00,
                    Status          = "Pending",
                    SiteManager     = manager1,
                    Supplier        = supplier1,
                    Site            = site1
                };
                context.PurchaseRequisitions.Add(requisition1);
                var requisitionItem1 = new PurchaseRequisitionItems {
                    Item = item1, PurchaseRequisition = requisition1, ItemCount = 3
                };
                var requisitionItem2 = new PurchaseRequisitionItems {
                    Item = item2, PurchaseRequisition = requisition1, ItemCount = 2
                };
                var requisitionItem3 = new PurchaseRequisitionItems {
                    Item = item3, PurchaseRequisition = requisition1, ItemCount = 1
                };
                context.Add(requisitionItem1);
                context.Add(requisitionItem2);
                context.Add(requisitionItem3);

                var order1 = new PurchaseOrder
                {
                    OrderReference  = 1,
                    ShippingAddress = "Malabe",
                    TotalCost       = 2000.00,
                    OrderStatus     = "IN PROCESS",
                    SiteManager     = manager1,
                    Supplier        = supplier1,
                    Site            = site1
                };
                context.PurchaseOrders.Add(order1);
                var orderItems1 = new PurchaseOrderItems {
                    Item = item1, PurchaseOrder = order1, ItemCount = 3
                };
                var orderItems2 = new PurchaseOrderItems {
                    Item = item2, PurchaseOrder = order1, ItemCount = 2
                };
                var orderItems3 = new PurchaseOrderItems {
                    Item = item3, PurchaseOrder = order1, ItemCount = 1
                };
                context.Add(orderItems1);
                context.Add(orderItems2);
                context.Add(orderItems3);

                var enquiry1 = new Enquiry {
                    EnquiryId = 1, Description = "Why order is late?", EnquiryStatus = "Pending", OrderReference = order1, SiteManager = manager1
                };
                var enquiry2 = new Enquiry {
                    EnquiryId = 2, Description = "Why order is late?", EnquiryStatus = "Pending", OrderReference = order1, SiteManager = manager1
                };
                var enquiry3 = new Enquiry {
                    EnquiryId = 3, Description = "Why order is late?", EnquiryStatus = "Pending", OrderReference = order1, SiteManager = manager1
                };
                context.Add(enquiry1);
                context.Add(enquiry2);
                context.Add(enquiry3);

                var delivery1 = new Delivery {
                    DeliveryId = "DL001", OnSiteDelivery = true, DeliveryStatus = "On Process", IsFullDelivery = true, Site = site1, PurchaseOrder = order1
                };
                context.Deliveries.Add(delivery1);

                var goodsReceipt1 = new GoodsReceipt {
                    ReceiptId = 1, PurchaseOrder = order1, Supplier = supplier1, Site = site1, Delivery = delivery1
                };
                context.GoodsReceipt.Add(goodsReceipt1);

                var invoice1 = new Invoice {
                    InvoiceId = "INV001", NetAmount = 2000.00, Description = "Order 1 invoice", GoodsReceipt = goodsReceipt1, Supplier = supplier1, InvoiceStatus = "Payment Due"
                };
                context.Invoice.Add(invoice1);

                context.SaveChanges();
            }
        }