public HttpResponseMessage PostContable(CargaMasivaCt model)
 {
     try
     {
         var rpta = _dContable.SaveFile(model);
         return(Request.CreateResponse(HttpStatusCode.OK, rpta));
     }
     catch
     {
         var message = "error al guardar carga de presupuestos, verifique los datos e intente nuevamente";
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, message));
     }
 }
Example #2
0
        public string SaveFile(CargaMasivaCt model)
        {
            string rpta = "";

            try
            {
                using (var ctx = new PresupuestoContext())
                {
                    using (var transaction = ctx.Database.BeginTransaction())
                    {
                        try
                        {
                            foreach (var m in model.detalle)
                            {
                                var newPsContalle = new SPPresupuestoContable
                                {
                                    Id              = model.Id,
                                    presupuestoId   = model.presupuestoId,
                                    subcentroId     = m.subcentroId,
                                    loteId          = m.loteId,
                                    cuenta_contable = m.cuenta_contable,
                                    codigo_cuenta   = m.codigo_cuenta,
                                    enero           = m.enero,
                                    febrero         = m.febrero,
                                    marzo           = m.marzo,
                                    abril           = m.abril,
                                    mayo            = m.mayo,
                                    junio           = m.junio,
                                    julio           = m.julio,
                                    agosto          = m.agosto,
                                    septiembre      = m.septiembre,
                                    octubre         = m.octubre,
                                    noviembre       = m.noviembre,
                                    diciembre       = m.diciembre,
                                    detalle         = m.detalle,
                                    total           = m.enero + m.febrero + m.marzo + m.abril + m.marzo + m.junio +
                                                      m.julio + m.agosto + m.septiembre + m.octubre + m.noviembre +
                                                      m.diciembre
                                };

                                ctx.Configuration.AutoDetectChangesEnabled = false;
                                ctx.SPPresupuestoContable.Add(newPsContalle);
                                ctx.SaveChanges();
                            }


                            transaction.Commit();
                            rpta = "Carga de datos realizada correctamente";
                        }
                        catch (Exception e)
                        {
                            transaction.Rollback();
                            throw e;
                        }
                    }
                }
            }catch (Exception e)
            {
                throw;
            }
            return(rpta);
        }