Ejemplo n.º 1
0
        public PersistenceResult AchitareFactura()
        {
            if (platiPeFactura == null)
            {
                platiPeFactura = new List <Plata>();
            }
            if (platiPeFactura.Count == 0)
            {
                return(new PersistenceResult
                {
                    Status = Enums.StatusEnum.Errors,
                    Message = "Nu ati adaugat nicio plata pentru aceasta factura!"
                });
            }
            var result = new PersistenceResult();

            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    foreach (var item in platiPeFactura)
                    {
                        var pr = item.Save();
                        if (pr.Status == Enums.StatusEnum.Errors)
                        {
                            throw new Exception(pr.Message, pr.ExceptionOccurred);
                        }
                        var plataFactura = new PlataFactura
                        {
                            IdFactura  = this.ID,
                            IdPlata    = item.ID,
                            TipFactura = "Iesire"
                        };
                        pr = plataFactura.Save();
                        if (pr.Status == Enums.StatusEnum.Errors)
                        {
                            throw new Exception(pr.Message, pr.ExceptionOccurred);
                        }
                    }
                    scope.Complete();
                    platiPeFactura = null;
                }
                result.Message = "Achitare factura reusita";
                result.Status  = Enums.StatusEnum.Saved;
            }
            catch (Exception ex)
            {
                Plata.plataList = null;
                PlataFactura.plataFacturaList = null;
                result.Message           = StringSaveFail;
                result.Status            = Enums.StatusEnum.Errors;
                result.ExceptionOccurred = ex;
            }
            return(result);
        }
Ejemplo n.º 2
0
 public PersistenceResult AchitareFactura()
 {
     if (platiPeFactura == null) platiPeFactura = new List<Plata>();
     if (platiPeFactura.Count == 0)
     {
         return new PersistenceResult
         {
             Status = Enums.StatusEnum.Errors,
             Message = "Nu ati adaugat nicio plata pentru aceasta factura!"
         };
     }
     var result = new PersistenceResult();
     try
     {
         using (TransactionScope scope = new TransactionScope())
         {
             foreach (var item in platiPeFactura)
             {
                 var pr = item.Save();
                 if (pr.Status == Enums.StatusEnum.Errors) throw new Exception(pr.Message, pr.ExceptionOccurred);
                 var plataFactura = new PlataFactura
                 {
                     IdFactura = this.ID,
                     IdPlata = item.ID,
                     TipFactura = "Iesire"
                 };
                 pr = plataFactura.Save();
                 if (pr.Status == Enums.StatusEnum.Errors) throw new Exception(pr.Message, pr.ExceptionOccurred);
             }
             scope.Complete();
             platiPeFactura = null;
         }
         result.Message = "Achitare factura reusita";
         result.Status = Enums.StatusEnum.Saved;
     }
     catch (Exception ex)
     {
         Plata.plataList = null;
         PlataFactura.plataFacturaList = null;
         result.Message = StringSaveFail;
         result.Status = Enums.StatusEnum.Errors;
         result.ExceptionOccurred = ex;
     }
     return result;
 }