public decimal CantitateDisponibila() { return((from s in Stoc.GetAll() where s.IdProdus == this.ID group s by s.NumeProdus into s_nou select s_nou.Sum(p => p.Cantitate)).FirstOrDefault()); }
public void InsertStocTest() { var target = new Stoc { IdPozitieFacturaIntrare =28, IdProdus = 2, Cantitate=30.123123m }; if (target.Save().Status == StatusEnum.Errors) { Assert.Fail(); } }
/// <summary> /// Id-ul pozitiei de intrare nu reflecta stocul insumat, deoarece un stoc poate contine produse din mai multe facturi de intrare. /// </summary> public static List <Stoc> GetAllGroupedByProdus(string produsName = "") { var query = from s in Stoc.GetAll() where s.NumeProdus.ToLower().Contains(produsName.ToLower()) group s by s.IdProdus into s_nou select new Stoc { ID = s_nou.Max(p => p.ID), Cantitate = s_nou.Sum(p => p.Cantitate), IdPozitieFacturaIntrare = s_nou.Select(p => p.IdPozitieFacturaIntrare).First(), IdProdus = s_nou.Select(p => p.IdProdus).First() }; return(query.ToList()); }
public void UpdateStocTest() { var target = new Stoc { IdPozitieFacturaIntrare = 1, IdProdus = 1, Cantitate=30, ID = 1 }; if (target.Save().Status == StatusEnum.Errors) { Assert.Fail(); } }
public PersistenceResult Save(List <PozitieFacturaIntrare> pozitieFacturaIntrareList) { // toate salvarea unei facturi de intrare reprezinta o tranzactie var persistenceResult = new PersistenceResult(); try { if (pozitieFacturaIntrareList.Count == 0) { return(new PersistenceResult { Message = "Nu ati adaugat niciun produs in factura!", Status = Enums.StatusEnum.Errors }); } using (TransactionScope scope = new TransactionScope()) { // salvez factura de intrare var facturaPersistenceResult = this.Save(); if (facturaPersistenceResult.Status == Enums.StatusEnum.Errors) { throw new Exception(facturaPersistenceResult.Message, facturaPersistenceResult.ExceptionOccurred); } int facturaIntrareId = this.ID; foreach (var pozitieFacturaIntrare in pozitieFacturaIntrareList) { // salvez fiecare pozitie factura intrare pozitieFacturaIntrare.IdFacturaIntrare = facturaIntrareId; var pozitieFacturaIntrarePersistenceResult = pozitieFacturaIntrare.Save(); if (pozitieFacturaIntrarePersistenceResult.Status == Enums.StatusEnum.Errors) { throw new Exception(pozitieFacturaIntrarePersistenceResult.Message, pozitieFacturaIntrarePersistenceResult.ExceptionOccurred); } var stocNou = new Stoc { IdPozitieFacturaIntrare = pozitieFacturaIntrare.ID, IdProdus = pozitieFacturaIntrare.IdProdus, Cantitate = pozitieFacturaIntrare.Cantitate }; var stocPersistenceResult = stocNou.Save(); if (stocPersistenceResult.Status == Enums.StatusEnum.Errors) { throw new Exception(stocPersistenceResult.Message, stocPersistenceResult.ExceptionOccurred); } } scope.Complete(); } persistenceResult.Status = Enums.StatusEnum.Saved; persistenceResult.Message = StringSaveSuccess; } catch (Exception ex) { FacturaIntrare.facturaIntrareList = null; PozitieFacturaIntrare.pozitieFacturaIntrareList = null; Stoc.stocList = null; persistenceResult.Status = Enums.StatusEnum.Errors; persistenceResult.ExceptionOccurred = ex; persistenceResult.Message = StringSaveFail; } return(persistenceResult); }
public PersistenceResult Save(List<PozitieFacturaIntrare> pozitieFacturaIntrareList) { // toate salvarea unei facturi de intrare reprezinta o tranzactie var persistenceResult = new PersistenceResult(); try { if (pozitieFacturaIntrareList.Count == 0) { return new PersistenceResult { Message = "Nu ati adaugat niciun produs in factura!", Status = Enums.StatusEnum.Errors }; } using (TransactionScope scope = new TransactionScope()) { // salvez factura de intrare var facturaPersistenceResult = this.Save(); if (facturaPersistenceResult.Status == Enums.StatusEnum.Errors) { throw new Exception(facturaPersistenceResult.Message, facturaPersistenceResult.ExceptionOccurred); } int facturaIntrareId = this.ID; foreach (var pozitieFacturaIntrare in pozitieFacturaIntrareList) { // salvez fiecare pozitie factura intrare pozitieFacturaIntrare.IdFacturaIntrare = facturaIntrareId; var pozitieFacturaIntrarePersistenceResult = pozitieFacturaIntrare.Save(); if (pozitieFacturaIntrarePersistenceResult.Status == Enums.StatusEnum.Errors) { throw new Exception(pozitieFacturaIntrarePersistenceResult.Message, pozitieFacturaIntrarePersistenceResult.ExceptionOccurred); } var stocNou = new Stoc { IdPozitieFacturaIntrare = pozitieFacturaIntrare.ID, IdProdus = pozitieFacturaIntrare.IdProdus, Cantitate = pozitieFacturaIntrare.Cantitate }; var stocPersistenceResult = stocNou.Save(); if (stocPersistenceResult.Status == Enums.StatusEnum.Errors) { throw new Exception(stocPersistenceResult.Message, stocPersistenceResult.ExceptionOccurred); } } scope.Complete(); } persistenceResult.Status = Enums.StatusEnum.Saved; persistenceResult.Message = StringSaveSuccess; } catch (Exception ex) { FacturaIntrare.facturaIntrareList = null; PozitieFacturaIntrare.pozitieFacturaIntrareList = null; Stoc.stocList = null; persistenceResult.Status = Enums.StatusEnum.Errors; persistenceResult.ExceptionOccurred = ex; persistenceResult.Message = StringSaveFail; } return persistenceResult; }