Exemplo n.º 1
0
 private string updateLot(ReceivingDetailModel model)
 {
     if (!string.IsNullOrEmpty(model.LotNo))
     {
         if (model.Id > 0)
         {
             ReceivingDetail savedDetail = service.GetSingleReceivingDetail(model.Id);
             LotNumber       savedLot    = lotService.GetSingle(model.LotNoId.ToString(), AuthenticationHelper.CompanyId.Value);
             if (savedLot.LotNo == model.LotNo)
             {
                 savedLot.Qty = savedLot.Qty - savedDetail.Quantity + model.ThisPurchaseQty;
                 return(lotService.Update(savedLot));
             }
             else
             {
                 List <LotNumber> savedLots = lotService.GetAllbyLotNo(AuthenticationHelper.CompanyId.Value, SessionHelper.SOBId, savedLot.LotNo, savedLot.ItemId).ToList();
                 if (savedLots.Count() > 1)
                 {
                     return("Lot can not be edited!");
                 }
                 else
                 {
                     savedLot.Qty   = savedLot.Qty - savedDetail.Quantity + model.ThisPurchaseQty;
                     savedLot.LotNo = model.LotNo;
                     return(lotService.Update(savedLot));
                 }
             }
         }
         else
         {
             LotNumber savedLot = lotService.GetLotbyItem(AuthenticationHelper.CompanyId.Value, SessionHelper.SOBId, model.ItemId, model.LotNo);
             if (savedLot != null)
             {
                 savedLot.Qty = savedLot.Qty + model.ThisPurchaseQty;
                 return(lotService.Update(savedLot));
             }
             else
             {
                 return(lotService.Insert(new LotNumber
                 {
                     CompanyId = AuthenticationHelper.CompanyId.Value,
                     CreateBy = AuthenticationHelper.UserId,
                     CreateDate = DateTime.Now,
                     ItemId = model.ItemId,
                     LotNo = model.LotNo,
                     Qty = model.ThisPurchaseQty,
                     SOBId = SessionHelper.SOBId,
                     SourceId = 0,
                     SourceType = "Receiving",
                     UpdateBy = null,
                     UpdateDate = null
                 }));
             }
         }
     }
     else
     {
         if (model.Id > 0)
         {
             ReceivingDetail  savedDetail = service.GetSingleReceivingDetail(model.Id);
             LotNumber        lot         = lotService.GetSingle(savedDetail.LotNoId.Value.ToString(), AuthenticationHelper.CompanyId.Value);
             List <LotNumber> savedLots   = lotService.GetAllbyLotNo(AuthenticationHelper.CompanyId.Value, SessionHelper.SOBId, lot.LotNo, lot.ItemId).ToList();
             if (savedDetail.LotNoId != null)
             {
                 if (savedLots.Count() > 1)
                 {
                     return("Lot can not be deleted!");
                 }
                 else
                 {
                     lotService.Delete(savedDetail.LotNoId.Value.ToString(), AuthenticationHelper.CompanyId.Value);
                 }
             }
             return("");
         }
         return("");
     }
 }