예제 #1
0
        public DeliveryActaViewModel ToDeliveryActaViewModel(DeliveryActa deliveryActa)
        {
            return(new DeliveryActaViewModel
            {
                Id = deliveryActa.Id,

                Usucrea = deliveryActa.Usucrea,

                StudentID = deliveryActa.Estudents.Id,
                Entrega3 = deliveryActa.Entrega3,
                Entrega4 = deliveryActa.Entrega4,
                Entrega5 = deliveryActa.Entrega5,
                Entrega6 = deliveryActa.Entrega6,
                Entrega7 = deliveryActa.Entrega7
            });
        }
예제 #2
0
        public async Task <IActionResult> PostActas(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var dateup = await _context.Sincros

                         .FirstOrDefaultAsync(o => o.Id == id.Value);

            if (dateup == null)
            {
                return(NotFound());
            }

            DateTime fullUpdate = Convert.ToDateTime(dateup.EndUpdate);

            try
            {
                var fileName = _context.DeliveryActas
                               .Where(s => s.FechaActualización > fullUpdate)
                               .ToList();



                if (fileName.Count > 0)
                {
                    int contadorSave   = 0;
                    int contadorUpdate = 0;

                    var       remoteDeliveryActas = cn.ActasServer(fullUpdate.ToString());
                    DataRow[] foundRows;

                    List <DeliveryActa> newActas = new List <DeliveryActa>();


                    foreach (var drs in fileName)
                    {
                        //Muestras los valores obteniendolos con el Índice o el Nombre de la columna,
                        //   de la siguiente manera:
                        bool     entrega3       = drs.Entrega3;
                        bool     entrega4       = drs.Entrega4;
                        bool     entrega5       = drs.Entrega5;
                        bool     entrega6       = drs.Entrega6;
                        bool     entrega7       = drs.Entrega7;
                        int      studentId      = drs.Estudents.Id;
                        DateTime dataUpdate     = drs.FechaActualización;
                        string   prefix         = drs.Prefix;
                        int      prefixSequence = drs.PrefixSequence;


                        foundRows = remoteDeliveryActas.Tables[0].Select($"Prefix = '{prefix}'&& prefixSequence ='{prefixSequence}' ");



                        if (foundRows == null)
                        {
                            DeliveryActa newActa = new DeliveryActa()
                            {
                                FechaActualización = Convert.ToDateTime(dataUpdate)
                            };
                            newActas.Add(newActa);
                            contadorSave++;
                        }


                        else
                        {
                            //Estudents updatedEstudent = await _context.Estudents.SingleAsync(t => t.Document == rdoc);
                            //if (Convert.ToDateTime(dataUpdate) > updatedEstudent.FechaActualización)
                            //{
                            //    updatedEstudent.NOrden = $"{updatedEstudent.NOrden}, {rnOder}";
                            //    updatedEstudent.Document = updatedEstudent.Document;
                            //    updatedEstudent.Sedes = await _context.Sedes.FindAsync(Convert.ToInt32(rsedes));
                            //    updatedEstudent.FullName = updatedEstudent.FullName;
                            //    updatedEstudent.AcudienteName = updatedEstudent.AcudienteName;
                            //    updatedEstudent.DocumentAcu = updatedEstudent.DocumentAcu;
                            //    updatedEstudent.AutDelivery = $"{updatedEstudent.AutDelivery}, {rautDelivery}";
                            //    updatedEstudent.Mesas = $"{updatedEstudent.Mesas}, {rmesas}";
                            //    updatedEstudent.Jornada = updatedEstudent.Jornada;
                            //    updatedEstudent.FechaActualización = Convert.ToDateTime(rdateUpdate);
                            //    contadorUpdate++;
                            //    _context.Estudents.Update(updatedEstudent);
                            //}
                        }
                    }



                    if (newActas.Any())
                    {
                        _context.DeliveryActas.AddRange(newActas);
                    }

                    await _context.SaveChangesAsync();

                    //ViewBag.Message = $"Se Encontraron {fileName.Tables[0].Rows.Count} Registros de los cuales {contadorSave} son Nuevos y {contadorUpdate} se actualizaron.";
                }
                else
                {
                    ViewBag.Message = $"No hay Registros Nuevos";
                }
                return(RedirectToAction($"Index"));
            }
            catch (Exception e)
            {
                string mensaje = "<script type='text/javascript'>alert('{0}')</script>";

                mensaje = string.Format(mensaje, $"Hola: {e.Message}");


                ViewBag.Message = $"Exeption: {e.Message}";
                return(RedirectToAction($"Index"));
            }
        }
예제 #3
0
        public async Task <IActionResult> GetActasList(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var dateup = await _context.Sincros

                         .FirstOrDefaultAsync(o => o.Id == id.Value);

            if (dateup == null)
            {
                return(NotFound());
            }

            string fullUpdate = dateup.EndUpdate;

            try
            {
                var fileName = cn.ActasServer(fullUpdate);

                if (fileName.Tables[0].Rows.Count > 0)
                {
                    int contadorSave                     = 0;
                    int contadorUpdate                   = 0;
                    var localDeliveryActas               = _context.DeliveryActas.ToList();
                    var localDetailsDeliveryActas        = _context.DetailsDeliveries.ToList();
                    List <DeliveryActa> newDeliveryActas = new List <DeliveryActa>();

                    List <Estudents> localStudents = await _context.Estudents.ToListAsync();

                    _context.ChangeTracker.AutoDetectChangesEnabled = false;

                    foreach (DataRow dr in fileName.Tables[0].Rows)
                    {
                        int    remoteActaId = (int)dr["Id"];
                        string entrega3     = dr["Entrega3"].ToString();
                        string entrega4     = dr["Entrega4"].ToString();
                        string entrega5     = dr["Entrega5"].ToString();
                        string entrega6     = dr["Entrega6"].ToString();
                        string entrega7     = dr["Entrega7"].ToString();
                        string doc          = dr["Document"].ToString();
                        int    idStudent    = Convert.ToInt32(dr["EstudentsId"]);
                        string dateUpdate   = dr["FechaActualización"].ToString();
                        string prefix       = dr["Prefix"].ToString();
                        int    numSequence  = Convert.ToInt32(dr["PrefixSequence"]);

                        DeliveryActa newOrUpdatedDeliveryActa = new DeliveryActa();


                        newOrUpdatedDeliveryActa = localDeliveryActas.SingleOrDefault(t => t.Prefix == prefix && t.PrefixSequence == numSequence);

                        if (newOrUpdatedDeliveryActa == null)
                        {
                            newOrUpdatedDeliveryActa = new DeliveryActa()
                            {
                                Entrega3           = Convert.ToBoolean(entrega3),
                                Entrega4           = Convert.ToBoolean(entrega4),
                                Entrega5           = Convert.ToBoolean(entrega5),
                                Entrega6           = Convert.ToBoolean(entrega6),
                                Entrega7           = Convert.ToBoolean(entrega7),
                                Estudents          = localStudents.Single(t => t.Document == doc),
                                Prefix             = prefix,
                                PrefixSequence     = numSequence,
                                FechaActualización = Convert.ToDateTime(dateUpdate)
                            };

                            _context.DeliveryActas.Add(newOrUpdatedDeliveryActa);

                            var remoteDetailActaRows = fileName.Tables[0].Rows.Cast <DataRow>().Where(detailDrs => (int)detailDrs["DeliveryActaId"] == remoteActaId).ToList();


                            foreach (DataRow detailDr in remoteDetailActaRows)
                            {
                                long     tel  = (long)detailDr["TelMovil"];
                                string   img1 = detailDr["Imagedocl"].ToString();
                                string   img2 = detailDr["Imagedoc2"].ToString();
                                DateTime date = Convert.ToDateTime(detailDr["FechaActualización"]);


                                DetailsDelivery newDetailsdeliveryActa = new DetailsDelivery()
                                {
                                    DeliveryActa = newOrUpdatedDeliveryActa,
                                    TelMovil     = tel,
                                    Imagedocl    = img1,
                                    Imagedoc2    = img2,

                                    FechaActualización = date
                                };


                                newOrUpdatedDeliveryActa.DetailsDeliveries.Add(newDetailsdeliveryActa);
                            }

                            contadorSave++;
                        }
                        else
                        {
                            if (Convert.ToDateTime(dateUpdate) > newOrUpdatedDeliveryActa.FechaActualización)
                            {
                                newOrUpdatedDeliveryActa.FechaActualización = Convert.ToDateTime(dateUpdate);
                                contadorUpdate++;
                            }
                        }
                    }

                    _context.ChangeTracker.AutoDetectChangesEnabled = true;
                    _context.ChangeTracker.DetectChanges();

                    await _context.SaveChangesAsync();

                    return(ViewBag.Success = $"Se Encontraron {fileName.Tables[0].Rows.Count} Registros de los cuales {contadorSave} son Nuevos y {contadorUpdate} se actualizaron.");
                }
                else
                {
                    ViewBag.Success = $"No hay Registros Nuevos";
                }
                return(RedirectToAction($"Index"));
            }
            catch (Exception e)
            {
                ViewBag.Message = $"Excepcion no Controlada: {e.Message} mas detalles:{e.InnerException}";
                return(RedirectToAction($"Index"));
            }
        }