예제 #1
0
        public static List <SupplierItemModel> ImportfromItemlistExcel(List <ImportSupplierItem> csp, out string error)
        {
            LUSSISEntities           entities           = new LUSSISEntities();
            List <SupplierItemModel> createdsupitemlist = new List <SupplierItemModel>();

            error = "";

            try
            {
                foreach (ImportSupplierItem sm in csp)
                {
                    SupplierModel spm = SupplierRepo.GetSupplierBySupname(sm.SupName, out string error1);

                    if (spm.SupName != "")
                    {
                        ItemModel im1 = ItemRepo.GetItemByItemDescription(sm.Description, out string error3);

                        if (im1.Description != "")
                        {
                            SupplierItemModel sim = GetSupplierItemListByItemIdandSupid(im1.Itemid, spm.SupId, out string error5);
                            if (sim.SupId != 0)
                            {
                                supplieritem supitem = entities.supplieritems
                                                       .Where(x => x.supid == spm.SupId &&
                                                              x.itemid == sim.ItemId).First();
                                supitem.price = sm.Price;
                                entities.SaveChanges();
                                createdsupitemlist.Add(GetSupplierItemListByItemIdandSupid(im1.Itemid, sim.SupId, out string error7));
                            }
                            else
                            {
                                supplieritem supitem = new supplieritem();
                                supitem.supid  = spm.SupId;
                                supitem.itemid = im1.Itemid;
                                supitem.price  = sm.Price;
                                entities.supplieritems.Add(supitem);
                                entities.SaveChanges();
                                createdsupitemlist.Add(GetSupplierItemListByItemIdandSupid(im1.Itemid, spm.SupId, out string error8));
                            }
                        }

                        else
                        {
                            item item = new item();


                            item.catid       = 21;
                            item.description = sm.Description;
                            item.uom         = sm.Uom;
                            item             = entities.items.Add(item);
                            entities.SaveChanges();

                            ItemModel im = ItemRepo.GetItemByItemid(item.itemid, out error);


                            inventory ivm = new inventory();
                            ivm.itemid       = im.Itemid;
                            ivm.stock        = 0;
                            ivm.reorderqty   = 0;
                            ivm.reorderlevel = 0;
                            ivm = entities.inventories.Add(ivm);
                            entities.SaveChanges();


                            supplieritem supitem = new supplieritem();
                            supitem.supid  = spm.SupId;
                            supitem.itemid = im.Itemid;
                            supitem.price  = sm.Price;
                            entities.supplieritems.Add(supitem);
                            entities.SaveChanges();
                            createdsupitemlist.Add(GetSupplierItemListByItemIdandSupid(im.Itemid, spm.SupId, out string error5));
                        }
                    }
                }
            }
            catch (Exception ex) {
                error = ex.Message;
            }
            return(createdsupitemlist);
        }