Exemple #1
0
 public void UpdateSupply(BusinessModels.Supply UpdSup)//Интеграционное
 {
     DAL.Supply UpdatedSupply = repos.Supplies.GetItem(UpdSup.Id);
     UpdatedSupply.StatusId = UpdSup.StatusId;
     if (UpdSup.StatusId == 2 || UpdSup.StatusId == 4 || UpdSup.StatusId == 5)
     {
         if (UpdSup.StatusId == 2)
         {
             List <BusinessModels.WarehouseLine> warehouselines = repos.WarehouseLines.GetList().Where(i => i.WarehouseId == UpdSup.WarehouseId).Select(i => new BusinessModels.WarehouseLine {
                 Id = i.Id, CommodityId = i.CommodityId
             }).ToList();
             foreach (BusinessModels.SupplyLine item in UpdSup.Lines)
             {
                 bool check = false;
                 foreach (BusinessModels.WarehouseLine wareline in warehouselines)
                 {
                     if (item.CommodityId == wareline.CommodityId)
                     {
                         DAL.WarehouseLine UpdatedLine = repos.WarehouseLines.GetItem(wareline.Id);
                         UpdatedLine.Quantity += item.Quantity;
                         repos.WarehouseLines.Update(UpdatedLine);
                         check = true;
                         break;
                     }
                 }
                 if (!check)
                 {
                     DAL.WarehouseLine NewLine = new DAL.WarehouseLine();
                     NewLine.Quantity    = item.Quantity;
                     NewLine.WarehouseId = UpdSup.WarehouseId;
                     NewLine.CommodityId = item.CommodityId;
                     NewLine.PerUnitCost = item.Cost / item.Quantity * 1.2m;
                     repos.WarehouseLines.Create(NewLine);
                 }
             }
         }
         UpdatedSupply.ArrangerId      = UpdSup.ArrangerId;
         UpdatedSupply.ArrangementDate = UpdSup.ArrangementDate;
     }
     repos.Supplies.Update(UpdatedSupply);
     repos.Save();
 }
Exemple #2
0
        public void CreateSupply(BLL.BusinessModels.Supply NewSupply)
        {
            DAL.Supply sup = new DAL.Supply()
            {
                Cost = NewSupply.Cost, ApplicantId = NewSupply.ApplicantId, ApplicationDate = DateTime.Now, DeliveryDate = NewSupply.DeliveryDate, ProviderId = NewSupply.ProviderId, WarehouseId = NewSupply.WarehouseId, StatusId = 1
            };
            List <DAL.SupplyLine> NewLines = new List <DAL.SupplyLine>();

            foreach (BusinessModels.SupplyLine i in NewSupply.Lines)
            {
                NewLines.Add(new DAL.SupplyLine()
                {
                    CommodityId = i.CommodityId, Quantity = i.Quantity, Cost = i.Cost * i.Quantity
                });
            }
            sup.SupplyLine = NewLines;
            repos.Supplies.Create(sup);
            repos.Save();
            NewSupply.Id = repos.Supplies.GetList().Last().Id;
        }