示例#1
0
        public dynamic Index(int?id)
        {
            EstadoList         EL    = new EstadoList();
            List <EstadoList>  LstEL = new List <EstadoList>();
            TareaIndex         TI    = new TareaIndex();
            ProyectList        PL    = new ProyectList();
            List <ProyectList> LstPL = new List <ProyectList>();

            try
            {
                DB = new SlabEntities();
                DB.Configuration.LazyLoadingEnabled = true;
                response     = new Response();
                LstEL.Add(EL = new EstadoList()
                {
                    Id = 0, Estado = "Pendiente"
                });
                LstEL.Add(EL = new EstadoList()
                {
                    Id = 1, Estado = "Realizada"
                });
                List <Proyecto> P = DB.Proyecto.ToList();
                List <Usuario>  U = DB.Usuario.ToList();
                Tarea           T = id != null?DB.Tarea.Where(x => x.Id == id).FirstOrDefault() : null;

                if (P != null)
                {
                    foreach (Proyecto p in P)
                    {
                        PL = new ProyectList()
                        {
                            Id          = p.Id,
                            Nombre      = p.Nombre,
                            Descripcion = p.Descripcion,
                            FechaInicio = p.Fecha_Inicio,
                            FechaFin    = p.Fecha_Fin,
                            Id_Operario = p.Id_Operario,
                            Operario    = U.Where(x => x.Id == p.Id_Operario).Select(x => x.Nombre + ' ' + x.Apellido).FirstOrDefault(),
                            Estado      = p.Estado,
                            ValEstado   = p.Estado == false ? "En Proceso" : "Finalizado"
                        };
                        LstPL.Add(PL);
                    }
                }
                TI = new TareaIndex()
                {
                    Id              = T != null ? T.Id : 0,
                    Nombre          = T != null ? T.Nombre : "",
                    Descripcion     = T != null ? T.Descripcion : "",
                    Fecha_Ejecucion = T != null ? T.Fecha_Ejecucion : DateTime.Now,
                    Id_Proyecto     = T != null ? T.Id_Proyecto : 0,
                    LstProyecto     = LstPL,
                    Estado          = T != null ? T.Estado == false ? 0 : 1 : 0,
                    ListaEstado     = LstEL
                };
                response.Successfully = true;
                response.Code         = 200;
                response.Message      = "Consulta realizada con éxito.";
                response.Result       = TI;
            }
            catch (Exception Exc)
            {
                response.Successfully = false;
                response.Code         = 500;
                response.Message      = Exc.Message.ToString();
                response.Result       = null;
            }
            return(response);
        }
示例#2
0
        public dynamic List(int?id)
        {
            #region Estados
            List <EstadoList> LstEL = new List <EstadoList>();
            EstadoList        EL    = new EstadoList();
            LstEL.Add(EL = new EstadoList()
            {
                Id = 0, Estado = "En Proceso"
            });
            LstEL.Add(EL = new EstadoList()
            {
                Id = 1, Estado = "Finalizado"
            });
            #endregion
            ProyectList        PL    = new ProyectList();
            List <ProyectList> LstPL = new List <ProyectList>();
            try
            {
                DB = new SlabEntities();
                DB.Configuration.LazyLoadingEnabled = true;
                response = new Response();
                List <Usuario>  Usr = DB.Usuario.ToList();
                List <Proyecto> Pro = id == null?DB.Proyecto.ToList() : DB.Proyecto.Where(x => x.Id == id).ToList();

                if (Pro.Count > 0)
                {
                    foreach (Proyecto P in Pro)
                    {
                        PL = new ProyectList()
                        {
                            Id          = P.Id,
                            Nombre      = P.Nombre,
                            Descripcion = P.Descripcion,
                            FechaInicio = P.Fecha_Inicio,
                            FechaFin    = P.Fecha_Fin,
                            Id_Operario = P.Id_Operario,
                            Operario    = Usr.Where(x => x.Id == P.Id_Operario).Select(x => x.Nombre + ' ' + x.Apellido).FirstOrDefault(),
                            Estado      = P.Estado,
                            ValEstado   = P.Estado == false ? "En Proceso" : "Finalizado"
                        };
                        LstPL.Add(PL);
                    }
                    response.Message = "";
                    response.Result  = LstPL;
                }
                else
                {
                    response.Message = "No se encontro ningun Proyecto";
                    response.Result  = null;
                }
                response.Successfully = true;
                response.Code         = 200;
            }
            catch (Exception Exc)
            {
                response.Successfully = false;
                response.Code         = 500;
                response.Message      = Exc.Message.ToString();
                response.Result       = null;
            }
            return(response);
        }
示例#3
0
 public dynamic Creacion(TareaEdit model)
 {
     #region Estados
     List <EstadoList> LstEL = new List <EstadoList>();
     EstadoList        EL    = new EstadoList();
     LstEL.Add(EL = new EstadoList()
     {
         Id = 0, Estado = "En Proceso"
     });
     LstEL.Add(EL = new EstadoList()
     {
         Id = 1, Estado = "Finalizado"
     });
     #endregion
     DB = new SlabEntities();
     DB.Configuration.LazyLoadingEnabled = true;
     response = new Response();
     using (var transaction = DB.Database.BeginTransaction())
     {
         try
         {
             Tarea    T   = DB.Tarea.Where(x => x.Nombre.ToUpper().Equals(model.Nombre.ToUpper()) && x.Descripcion.ToUpper().Equals(model.Descripcion.ToUpper()) && x.Id_Proyecto == model.Id_Proyecto).FirstOrDefault();
             Proyecto Pro = DB.Proyecto.Where(x => x.Id == model.Id_Proyecto).FirstOrDefault();
             if (T == null)
             {
                 if (Pro.Fecha_Fin >= model.Fecha_Ejecucion && Pro.Fecha_Inicio <= model.Fecha_Ejecucion)
                 {
                     var ValEstado = LstEL.Where(x => x.Id == model.Estado).FirstOrDefault();
                     if (ValEstado != null)
                     {
                         T = new Tarea()
                         {
                             Nombre          = model.Nombre,
                             Descripcion     = model.Descripcion,
                             Fecha_Ejecucion = model.Fecha_Ejecucion,
                             Id_Proyecto     = model.Id_Proyecto,
                             Estado          = model.Estado == 1 ? true : false
                         };
                         DB.Tarea.Add(T);
                         DB.SaveChanges();
                         response.Successfully = true;
                         response.Code         = 201;
                         response.Message      = "Tarea Insertada con éxito.";
                         response.Result       = "Successfully";
                         transaction.Commit();
                     }
                     else
                     {
                         response.Successfully = false;
                         response.Code         = 403;
                         response.Message      = "El estado enviado no existe.";
                         response.Result       = "";
                     }
                 }
                 else
                 {
                     response.Successfully = false;
                     response.Code         = 403;
                     response.Message      = "La fecha de ejecucion de la tarea excede la fecha de inicio/finalizacion del proyecto o es menor a la fecha actual.";
                     response.Result       = "";
                 }
             }
             else
             {
                 response.Successfully = false;
                 response.Code         = 200;
                 response.Message      = string.Format("Ya existe un Proyecto con ese nombre {0} y con esa descripcion {1}", model.Nombre, model.Descripcion);
                 response.Result       = null;
             }
         }
         catch (Exception Exc)
         {
             transaction.Rollback();
             response.Successfully = false;
             response.Code         = 400;
             response.Message      = "Error In the Method, Error: " + Exc.Message.ToString();
             response.Result       = "Error in the Method";
         }
     }
     return(response);
 }
示例#4
0
        public dynamic ChangeEstado(int id)
        {
            DB = new SlabEntities();
            DB.Configuration.LazyLoadingEnabled = true;
            response = new Response();
            bool TComplete = true;

            using (var transaction = DB.Database.BeginTransaction())
            {
                try
                {
                    Proyecto       PR   = DB.Proyecto.Where(x => x.Id == id).FirstOrDefault();
                    List <Tarea>   T    = DB.Tarea.Where(x => x.Id_Proyecto == id).ToList();
                    int            R    = DB.Rol.Where(x => x.Rol1.ToUpper().Equals("ADMINISTRADOR")).Select(x => x.Id).FirstOrDefault();
                    List <Usuario> LstU = DB.Usuario.Where(x => x.Rol_Id == R).ToList();
                    if (PR != null)
                    {
                        if (PR.Estado == false)
                        {
                            foreach (Tarea tarea in T)
                            {
                                if (tarea.Estado == false)
                                {
                                    TComplete = false;
                                }
                            }
                            if (TComplete)
                            {
                                PR.Estado          = true;
                                DB.Entry(PR).State = EntityState.Modified;
                                DB.SaveChanges();
                                response.Successfully = true;
                                response.Code         = 200;
                                response.Message      = "Actualización del estad del proyecto realizado con éxito.";
                                response.Result       = "Successfully";
                                #region Email
                                var msg = new MailMessage();
                                foreach (Usuario U in LstU)
                                {
                                    msg.To.Add(new MailAddress(U.Correo));
                                }
                                msg.From = new MailAddress(ConfigurationManager.AppSettings["MailFrom"]);
                                string fromPassword = ConfigurationManager.AppSettings["MailPassword"];
                                msg.Subject = "Proyecto finalizado.";
                                msg.Body    = "El proyecto: " + PR.Nombre + ", ha finalizado con exito.";

                                var smtp = new SmtpClient
                                {
                                    Host                  = "smtp.gmail.com",
                                    Port                  = 587,
                                    EnableSsl             = true,
                                    DeliveryMethod        = SmtpDeliveryMethod.Network,
                                    UseDefaultCredentials = false,
                                    Credentials           = new NetworkCredential(msg.From.Address, fromPassword)
                                };
                                smtp.Send(msg);
                                #endregion
                                transaction.Commit();
                            }
                            else
                            {
                                response.Successfully = false;
                                response.Code         = 200;
                                response.Message      = "Hay tareas por finalizar.";
                                response.Result       = null;
                            }
                        }
                        else
                        {
                            response.Successfully = false;
                            response.Code         = 200;
                            response.Message      = "El proyecto ya esta finalizado.";
                            response.Result       = null;
                        }
                    }
                    else
                    {
                        response.Successfully = false;
                        response.Code         = 200;
                        response.Message      = "No se logró validar el Proyecto.";
                        response.Result       = null;
                    }
                }
                catch (Exception Ex)
                {
                    response.Successfully = false;
                    response.Code         = 500;
                    response.Message      = Ex.Message.ToString();
                    response.Result       = null;
                }
            }
            return(response);
        }
示例#5
0
        public dynamic Actualizacion(ProyectoEdit model)
        {
            bool OkFechas = true;

            DB = new SlabEntities();
            DB.Configuration.LazyLoadingEnabled = true;
            response = new Response();
            using (var transaction = DB.Database.BeginTransaction())
            {
                try
                {
                    Proyecto     PR = DB.Proyecto.Where(x => x.Id == model.Id).FirstOrDefault();
                    List <Tarea> T  = DB.Tarea.Where(x => x.Id_Proyecto == model.Id).ToList();
                    if (PR != null)
                    {
                        foreach (Tarea tarea in T)
                        {
                            if (tarea.Fecha_Ejecucion > PR.Fecha_Fin)
                            {
                                OkFechas = false;
                            }
                        }
                        if (OkFechas)
                        {
                            PR.Nombre          = model.Nombre;
                            PR.Descripcion     = model.Descripcion;
                            PR.Fecha_Fin       = model.FechaFin;
                            DB.Entry(PR).State = EntityState.Modified;
                            DB.SaveChanges();
                            response.Successfully = true;
                            response.Code         = 200;
                            response.Message      = "Actualización de datos realizada con éxito.";
                            response.Result       = "Successfully";
                            transaction.Commit();
                        }
                        else
                        {
                            response.Successfully = false;
                            response.Code         = 200;
                            response.Message      = "La fecha final del proyecto no puede ser anterior a las tareas asignadas a este.";
                            response.Result       = null;
                        }
                    }
                    else
                    {
                        response.Successfully = false;
                        response.Code         = 200;
                        response.Message      = "No se logró validar el Proyecto.";
                        response.Result       = null;
                    }
                }
                catch (Exception Ex)
                {
                    response.Successfully = false;
                    response.Code         = 500;
                    response.Message      = Ex.Message.ToString();
                    response.Result       = null;
                }
            }
            return(response);
        }
示例#6
0
        public dynamic Index(int?id)
        {
            #region Estados
            List <EstadoList> LstEL = new List <EstadoList>();
            EstadoList        EL    = new EstadoList();
            LstEL.Add(EL = new EstadoList()
            {
                Id = 0, Estado = "En Proceso"
            });
            LstEL.Add(EL = new EstadoList()
            {
                Id = 1, Estado = "Finalizado"
            });
            #endregion
            ProyectoIndex      PI    = new ProyectoIndex();
            UsuarioList        UL    = new UsuarioList();
            List <UsuarioList> LstUL = new List <UsuarioList>();
            try
            {
                DB = new SlabEntities();
                DB.Configuration.LazyLoadingEnabled = true;
                response = new Response();
                Rol            R = DB.Rol.Where(y => y.Rol1.ToUpper().Equals("OPERARIO")).FirstOrDefault();
                List <Usuario> U = DB.Usuario.Where(x => x.Rol_Id == R.Id && x.Estado == true).ToList();
                Proyecto       P = id != null?DB.Proyecto.Where(x => x.Id == id).FirstOrDefault() : null;

                if (U != null)
                {
                    foreach (Usuario usr in U)
                    {
                        UL = new UsuarioList()
                        {
                            Id       = usr.Id,
                            Nombre   = usr.Nombre,
                            Apellido = usr.Apellido,
                            Correo   = usr.Correo,
                            Usuario  = usr.Usuario1,
                        };
                        LstUL.Add(UL);
                    }
                }
                PI = new ProyectoIndex()
                {
                    Id          = P != null ? P.Id : 0,
                    Nombre      = P != null ? P.Nombre : "",
                    Descripcion = P != null ? P.Descripcion : "",
                    FechaInicio = P != null ? P.Fecha_Inicio : DateTime.Now,
                    FechaFin    = P != null ? P.Fecha_Fin : DateTime.Now,
                    Estado      = P != null ? P.Estado == false ? 0 : 1 : 0,
                    LstEstado   = LstEL
                };
                response.Successfully = true;
                response.Code         = 200;
                response.Message      = "Consulta realizada con éxito.";
                response.Result       = PI;
            }
            catch (Exception Exc)
            {
                response.Successfully = false;
                response.Code         = 500;
                response.Message      = Exc.Message.ToString();
                response.Result       = null;
            }
            return(response);
        }
示例#7
0
        public dynamic List(int?id)
        {
            #region Estados
            List <EstadoList> LstEL = new List <EstadoList>();
            EstadoList        EL    = new EstadoList();
            LstEL.Add(EL = new EstadoList()
            {
                Id = 0, Estado = "Inactivo"
            });
            LstEL.Add(EL = new EstadoList()
            {
                Id = 1, Estado = "Activo"
            });
            #endregion
            UsuarioList        UL    = new UsuarioList();
            List <UsuarioList> LstUL = new List <UsuarioList>();
            try
            {
                DB = new SlabEntities();
                DB.Configuration.LazyLoadingEnabled = true;
                response = new Response();
                List <Rol>     R   = DB.Rol.ToList();
                List <Usuario> Usr = id == null?DB.Usuario.ToList() : DB.Usuario.Where(x => x.Id == id).ToList();

                if (Usr.Count > 0)
                {
                    foreach (Usuario U in Usr)
                    {
                        UL = new UsuarioList()
                        {
                            Id       = U.Id,
                            Nombre   = U.Nombre,
                            Apellido = U.Apellido,
                            Correo   = U.Correo,
                            Rol_Id   = U.Rol_Id,
                            Rol      = R?.Where(x => x.Id == U.Rol_Id).Select(x => x.Rol1).FirstOrDefault(),
                            Usuario  = U.Usuario1,
                            Estado   = U.Estado == false ? "Inactivo" : "Activo"
                        };
                        LstUL.Add(UL);
                    }
                    response.Message = "";
                    response.Result  = LstUL;
                }
                else
                {
                    response.Message = "No se encontro ningun Usuario";
                    response.Result  = null;
                }
                response.Successfully = true;
                response.Code         = 200;
            }
            catch (Exception Exc)
            {
                response.Successfully = false;
                response.Code         = 500;
                response.Message      = Exc.Message.ToString();
                response.Result       = null;
            }
            return(response);
        }
示例#8
0
        public dynamic Creacion(UsuarioEdit model)
        {
            #region Estados
            List <EstadoList> LstEL = new List <EstadoList>();
            EstadoList        EL    = new EstadoList();
            LstEL.Add(EL = new EstadoList()
            {
                Id = 0, Estado = "Inactivo"
            });
            LstEL.Add(EL = new EstadoList()
            {
                Id = 1, Estado = "Activo"
            });
            #endregion
            DB       = new SlabEntities();
            response = new Response();
            using (var transaction = DB.Database.BeginTransaction())
            {
                try
                {
                    Usuario User = DB.Usuario.Where(x => x.Usuario1.ToUpper().Equals(model.Usuario.ToUpper()) && x.Correo.ToUpper().Equals(model.Correo.ToUpper()) && x.Rol_Id == model.Rol_Id).FirstOrDefault();
                    if (User == null && LstEL.Where(x => x.Id == model.Estado).FirstOrDefault() != null)
                    {
                        User = new Usuario()
                        {
                            Nombre     = model.Nombre,
                            Apellido   = model.Apellido,
                            Rol_Id     = DB.Rol.Where(x => x.Rol1.ToUpper().Equals("OPERARIO")).Select(x => x.Id).FirstOrDefault(),
                            Usuario1   = model.Usuario,
                            Correo     = model.Correo,
                            Contrasena = response.Encriptar("Slab" + model.Usuario + "Code"),
                            Estado     = model.Estado == 0 ? false : true
                        };
                        DB.Usuario.Add(User);
                        DB.SaveChanges();
                        #region Email
                        var          fromAddress  = new MailAddress(ConfigurationManager.AppSettings["MailFrom"], "Slab Code");
                        var          toAddress    = new MailAddress(model.Correo, model.Nombre + ' ' + model.Apellido);
                        string       fromPassword = ConfigurationManager.AppSettings["MailPassword"];
                        const string subject      = "Creacion de Usuario en SlabCode.";
                        string       body         = "Su usuario es: " + model.Usuario + " y su contraseña es: " + "Slab" + model.Usuario + "Code";

                        var smtp = new SmtpClient
                        {
                            Host                  = "smtp.gmail.com",
                            Port                  = 587,
                            EnableSsl             = true,
                            DeliveryMethod        = SmtpDeliveryMethod.Network,
                            UseDefaultCredentials = false,
                            Credentials           = new NetworkCredential(fromAddress.Address, fromPassword)
                        };
                        using (var message = new MailMessage(fromAddress, toAddress)
                        {
                            Subject = subject,
                            Body = body
                        })
                        {
                            smtp.Send(message);
                        }
                        #endregion
                        response.Successfully = true;
                        response.Code         = 201;
                        response.Message      = "Usuario Insertado con éxito.";
                        response.Result       = "Successfully";
                        transaction.Commit();
                    }
                    else
                    {
                        response.Successfully = false;
                        response.Code         = 200;
                        response.Message      = string.Format("Ya existe un Usuario con ese usuario {0}, con ese correo {1} o la informacion enviada es incorrecta.", model.Usuario, model.Correo);
                        response.Result       = null;
                    }
                }
                catch (Exception Exc)
                {
                    transaction.Rollback();
                    response.Successfully = false;
                    response.Code         = 400;
                    response.Message      = "Error In the Method, Error: " + Exc.Message.ToString();
                    response.Result       = "Error in the Method";
                }
            }
            return(response);
        }