Exemplo n.º 1
0
        private static List<ContactoModel> GetById(Guid id)
        {
            var lContactos = new List<ContactoModel>();
            try
            {
                using (AgendaEntities dbContext = new AgendaEntities())
                {
                    var rContactos = dbContext.Contacto.Where(x => (bool)x.Activo && x.Id == id).ToList();

                    rContactos.ForEach(x => lContactos.Add(new ContactoModel()
                    {
                        ApellidoMaterno = x.ApellidoMaterno,
                        ApellidoPaterno = x.ApellidoPaterno,
                        Direccion = x.Direccion,
                        Email = x.Email,
                        Nombre = x.Nombre,
                        Telefono = x.Telefono
                    }));

                    return lContactos;
                }
            }
            catch
            {
                return lContactos; 
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns a list of events from the Database based on a time choice
        /// </summary>
        /// <param name="date"></param>
        /// <param name="dayOrWeek"></param>
        /// <returns></returns>
        public List <Event> GetRecordsFromDB(DateTime date, string dayOrWeek)
        {
            List <Event>   events    = null;
            AgendaEntities context   = new AgendaEntities();
            DateTime       limitDate = date.Date.AddDays(7);

            try
            {
                if (dayOrWeek.ToLower() == "day")
                {
                    events = context.Events.Where(e => e.Date == date.Date).ToList();
                }
                else if (dayOrWeek.ToLower() == "week")
                {
                    events = context.Events.Where(e => e.Date >= date.Date.Date && e.Date < limitDate.Date).ToList();
                }
                else if (dayOrWeek.ToLower() == "all")
                {
                    events = context.Events.Where(e => e.Id > 0).ToList();
                }
            }catch (Exception e)
            {
                MessageBox.Show("Exception Details: " + e);
            }
            return(events);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Will return TRUE if the user introduced data is matching with the data from database
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public bool ValidateUser(string username, string password)
        {
            bool           validation = true;
            AgendaEntities db         = new AgendaEntities();

            try
            {
                if (username != string.Empty || password != string.Empty)
                {
                    var user = db.USER.Where(u => u.Username == username).FirstOrDefault();

                    if (user != null)
                    {
                        if (user.Password.Equals(password))
                        {
                            return(validation);
                        }
                    }
                }
                else
                {
                    return(!validation);
                }
            } catch (Exception e)
            {
                MessageBox.Show("Exception Details: " + e);
            }

            return(!validation);
        }
Exemplo n.º 4
0
        // GET: api/MK_SCORE_PARTY
        public IQueryable <MK_SCORE_PARTY> GetMK_SCORE_PARTY()
        {
            ImportBillVotesByAgenda();
            using (AgendaEntities db = new AgendaEntities())
            {
                // http://www.asp.net/web-api/overview/data/using-web-api-with-entity-framework/part-5
                var MK_SCORE_PARTYs = from mk_s in db.MK_SCORE
                                      join mk_p in db.MK_TO_PARTY on mk_s.mk equals mk_p.mk
                                      select new MK_SCORE_PARTY()
                {
                    IdMK_SCORE    = mk_s.Id,
                    mk            = mk_s.mk,
                    mkName        = mk_s.MK1.mk_name,
                    party         = mk_p.party,
                    partyName     = mk_p.PARTY1.party1,
                    fromDate      = mk_s.fromDate,
                    toDate        = mk_s.toDate,
                    knessetNumber = mk_p.knessetNumber,
                    score         = mk_s.score,
                    volume        = mk_s.volume,
                    agendaId      = mk_s.agendaId,
                    agendaName    = mk_s.AGENDA.name
                };

                return(MK_SCORE_PARTYs);
            }
        }
Exemplo n.º 5
0
        public static bool Excluir(Pessoa p)
        {
            try
            {
                AgendaEntities db = new AgendaEntities();
                Pessoa         pa = new Pessoa();

                pa = db.Pessoas.Find(p.Email);

                if (pa != null)
                {
                    db.Pessoas.Remove(pa);
                }
                else
                {
                    return(false);
                }

                db.SaveChanges();

                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 6
0
        private static List<ContactoModel> GetBy_Email(string email)
        {
            var lContactos = new List<ContactoModel>();
            try
            {
                if (string.IsNullOrEmpty(email)) return lContactos;

                using (AgendaEntities dbContext = new AgendaEntities())
                {
                    var rContactos = dbContext.Contacto.Where(x => (bool)x.Activo && x.Email.Trim().ToUpper() == email.Trim().ToUpper()).ToList();

                    rContactos.ForEach(x => lContactos.Add(new ContactoModel()
                    {
                        ApellidoMaterno = x.ApellidoMaterno,
                        ApellidoPaterno = x.ApellidoPaterno,
                        Direccion = x.Direccion,
                        Email = x.Email,
                        Nombre = x.Nombre,
                        Telefono = x.Telefono
                    }));

                    return lContactos;
                }
            }
            catch
            {
                return lContactos;
            }
        }
Exemplo n.º 7
0
        public Tarea getTaskById(int Id)
        {
            var task = new Tarea();

            using (var conexion = new AgendaEntities())
            {
                task = conexion.Tareas.FirstOrDefault(x => x.ID == Id);
            }
            return(task);
        }
Exemplo n.º 8
0
        public List <Tarea> getallTask()
        {
            var List = new List <Tarea>();

            using (var conexion = new AgendaEntities())
            {
                List = conexion.Tareas.ToList();
            }
            return(List);
        }
Exemplo n.º 9
0
 /// <summary>
 ///  recalculate the general score of every agenda
 /// </summary>
 private void recalculate(DateTime from, DateTime to)
 {
     using (AgendaEntities db = new AgendaEntities())
     {
         foreach (AGENDA a in db.AGENDA)
         {
             recalculate(a.Id, from, to);
         }
     }
 }
Exemplo n.º 10
0
        public static OperationResult Create(ContactoModel contacto)
        {
            try
            {
                #region Validaciones
                if (contacto == null) return new OperationResult() { Message = "El objeto Contacto viene vacío"};
                if (string.IsNullOrEmpty(contacto.Nombre)) return new OperationResult() { Message = "El nombre es requerido" };
                if (string.IsNullOrEmpty(contacto.ApellidoPaterno)) return new OperationResult() { Message = "El apellido paterno es requerido" };
                if (string.IsNullOrEmpty(contacto.Telefono)) return new OperationResult() { Message = "El teléfono es requerido" };
                if (contacto.Nombre.Length > 50) return new OperationResult() { Message = "El nombre debe tener 50 caracteres como máximo" };
                if (contacto.ApellidoPaterno.Length > 50) return new OperationResult() { Message = "El apellido debe tener 50 caracteres como máximo" };
                if (!string.IsNullOrEmpty(contacto.ApellidoMaterno))
                {
                    if (contacto.ApellidoMaterno.Length > 50) return new OperationResult() { Message = "El apellido debe tener 50 caracteres como máximo" };
                }     
                if (contacto.Telefono.Length > 16) return new OperationResult() { Message = "El teléfono debe tener 16 caracteres como máximo" };
                if (!string.IsNullOrEmpty(contacto.Direccion))
                {
                    if (contacto.Direccion.Length > 100) return new OperationResult() { Message = "La dirección debe tener 100 caracteres como máximo" };
                }                   

                var contactosTel = GetBy_Tel(contacto.Telefono);
                if (contactosTel.Any()) return new OperationResult() { Message = "El número de teléfono ya ha sido registrado anteriormente." };

                var contactosEmail = GetBy_Email(contacto.Email);
                if (contactosEmail.Any()) return new OperationResult() { Message = "El correo electrónico ya ha sido registrado anteriormente." };
                #endregion

                using (AgendaEntities dbContext = new AgendaEntities())
                {
                    dbContext.Contacto.Add(new Contacto() { 
                    
                        Activo = true,
                        ApellidoMaterno = contacto.ApellidoMaterno,
                        ApellidoPaterno =  contacto.ApellidoPaterno,
                        Direccion = contacto.Direccion,
                        Email = contacto.Email,
                        FechaCreacion = DateTime.Now,
                        Id = Guid.NewGuid(),
                        Nombre = contacto.Nombre,
                        Telefono = contacto.Telefono

                    });

                    dbContext.SaveChanges();

                    return new OperationResult() { Success = true };
                }
            }
            catch (Exception ex)
            {               
                return new OperationResult() { Message = ex.Message }; // Normalmente se manda un error genérico, pero se deja así por fines de que es una evaluación
            }
        }
Exemplo n.º 11
0
        public bool addTask(Tarea task)
        {
            var retorno = false;

            using (var conexion = new AgendaEntities())
            {
                conexion.Tareas.Add(task);
                conexion.SaveChanges();
                retorno = true;
            }
            return(retorno);
        }
Exemplo n.º 12
0
 public static List <Pessoa> Listar()
 {
     try
     {
         AgendaEntities db = new AgendaEntities();
         return(db.Pessoas.ToList());
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 13
0
        public bool updateTask(int ID)
        {
            var retorno = false;

            using (var conexion = new AgendaEntities())
            {
                var t = conexion.Tareas.FirstOrDefault(x => x.ID == ID);
                t.estado = (t.estado) ? false : true;
                conexion.SaveChanges();
                retorno = true;
            }
            return(retorno);
        }
Exemplo n.º 14
0
        public bool deletedTask(int ID)
        {
            var retorno = false;

            using (var conexion = new AgendaEntities())
            {
                var t = conexion.Tareas.FirstOrDefault(x => x.ID == ID);
                conexion.Tareas.Remove(t);
                conexion.SaveChanges();
                retorno = true;
            }
            return(retorno);
        }
Exemplo n.º 15
0
        public static Pessoa Pesquisar(String email)
        {
            try
            {
                AgendaEntities db = new AgendaEntities();


                return(db.Pessoas.Find(email));
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 16
0
        protected void RegisterUser_CreatedUser(object sender, EventArgs e)
        {
            AgendaEntities agenda   = new AgendaEntities();
            Usuarios       usuarios = new Usuarios();

            usuarios.Nome  = RegisterUser.UserName.ToString();
            usuarios.Email = RegisterUser.Email.ToString();
            usuarios.Senha = RegisterUser.Password.ToString();

            agenda.AddToUsuarios(usuarios);
            agenda.SaveChanges();

            Response.Redirect("Login.aspx");
        }
Exemplo n.º 17
0
        public static Pessoa Pesquisar(Guid userid)
        {
            try
            {
                AgendaEntities db = new AgendaEntities();


                return(db.Pessoas.Find(userid));
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 18
0
        public static Pessoa Pesquisar(string email)
        {
            try
            {
                AgendaEntities db = new AgendaEntities();
                Pessoa         pa = new Pessoa();

                pa = db.Pessoas.Find(email);
                return(pa);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 19
0
        public static bool Inserir(Pessoa p)
        {
            try
            {
                AgendaEntities db = new AgendaEntities();

                db.Pessoas.Add(p);
                db.SaveChanges();

                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
        protected void LoginButton_Click(object sender, EventArgs e)
        {
            AgendaEntities agenda = new AgendaEntities();
            string         login  = LoginUser.UserName.ToString();
            string         senha  = LoginUser.Password.ToString();

            var usr = agenda.Usuarios.Where(u => u.Email.Equals(login) && u.Senha.Equals(senha)).FirstOrDefault();

            if (usr != null)
            {
                FormsAuthentication.SetAuthCookie(usr.Nome.ToString(), false);
                Session["codigo"]  = usr.Id.ToString();
                Session["usuario"] = usr.Nome.ToString();
                Response.Redirect("~/Contatos.aspx");
            }
        }
Exemplo n.º 21
0
        public static Pessoa Pesquisar(String email)
        {
            try
            {
                AgendaEntities db = new AgendaEntities();
                Pessoa         pa = new Pessoa();

                // Para alterar o registro é necessário ler primeiro e depois fazer modificações
                pa = db.Pessoas.Find(email);

                return(pa);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// Will delete a record(event) from the database based on a given ID
        /// </summary>
        /// <param name="id"></param>
        public void DeleteRecordFromDB(int id)
        {
            AgendaEntities context = new AgendaEntities();

            try
            {
                var eventToRemove = context.Events.FirstOrDefault(e => e.Id == id);

                if (eventToRemove != null)
                {
                    context.Events.Remove(eventToRemove);
                    context.SaveChanges();
                }
            }catch (Exception e)
            {
                MessageBox.Show("Exception Details: " + e);
            }
        }
Exemplo n.º 23
0
        public static bool Inserir(Pessoa p)
        {
            try
            {
                AgendaEntities db = new AgendaEntities();
                if (pnAgenda.Pesquisar(p.Email) != null)
                {
                    return(false);
                }
                db.Pessoas.Add(p);
                db.SaveChanges();

                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 24
0
        public static bool Excluir(Pessoa p)
        {
            try
            {
                AgendaEntities db = new AgendaEntities();
                Pessoa         pa = new Pessoa();

                // Para excluir o registro é necessário ler primeiro e depois fazer modificações
                pa = db.Pessoas.Find(p.Email);

                db.Pessoas.Remove(pa);
                db.SaveChanges();

                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 25
0
        public static bool Alterar(Pessoa p)
        {
            try
            {
                AgendaEntities db = new AgendaEntities();
                Pessoa         pa = new Pessoa();

                pa = db.Pessoas.Find(p.UserID);

                pa.Idade = p.Idade;
                pa.Nome  = p.Nome;

                db.SaveChanges();

                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 26
0
        public static OperationResult Delete(Guid id)
        {
            try
            {
                using (AgendaEntities dbContext = new AgendaEntities())
                {
                    var rContactos = dbContext.Contacto.Where(x => (bool)x.Activo && x.Id == id).ToList();
                    if (!rContactos.Any()) return new OperationResult() { Message = "El contacto con el id ingresado no existe. Verifique." };

                    rContactos.First().Activo = false;

                    dbContext.SaveChanges();

                    return new OperationResult() { Success = true };
                }
            }
            catch(Exception ex) // Normalmente se manda un error genérico, pero se deja así por fines de que es una evaluación
            {
                return new OperationResult() { Message = ex.Message };
            }
        }
Exemplo n.º 27
0
        public static ResponseContactoModel Get(int numRegistros, int numPagina, string filter)
        {
            var rContactos_ = new ResponseContactoModel();

            try
            {
                using (AgendaEntities dbContext = new AgendaEntities())
                {
                    if (string.IsNullOrEmpty(filter)) filter = "";

                    var rContactos = dbContext.Contacto.Where(x => (bool)x.Activo &&
                    (((x.Nombre ?? "") + " " + (x.ApellidoPaterno ?? "") + " " + (x.ApellidoMaterno ?? "")).Contains(filter) || 
                    x.Email.Contains(filter) ||
                    x.Telefono.Contains(filter) ||
                    x.Direccion.Contains(filter)))
                        .OrderByDescending(x => x.FechaCreacion).ToList();

                    rContactos_.TotalGlobal = rContactos.Count();

                    rContactos = rContactos.Skip((numPagina - 1) * numRegistros)
                   .Take(numRegistros).ToList();

                    rContactos.ForEach(x => rContactos_.ListContactos.Add(new ContactoModel() {                     
                        ApellidoMaterno = x.ApellidoMaterno,
                        ApellidoPaterno = x.ApellidoPaterno,
                        Direccion = x.Direccion,
                        Email = x.Email,
                        Nombre = x.Nombre,
                        Telefono = x.Telefono,
                        Id = x.Id
                    }));

                    return rContactos_;
                }
            }
            catch 
            {
                return rContactos_; // Normalmente se manda un error genérico, pero se deja así por fines de que es una evaluación
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// Will edit a record(event) from the database
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <param name="date"></param>
        /// <param name="time"></param>
        /// <param name="description"></param>
        public void UpdateRecord(int id, string name, DateTime date, DateTime time, string description)
        {
            try
            {
                using (var context = new AgendaEntities())
                {
                    var evnt = context.Events.SingleOrDefault(e => e.Id == id);
                    if (evnt != null)
                    {
                        evnt.Name        = name;
                        evnt.Date        = date;
                        evnt.Time        = time.TimeOfDay;
                        evnt.Description = description;

                        context.SaveChanges();
                    }
                }
            }catch (Exception e)
            {
                MessageBox.Show("Exception Details: " + e);
            }
        }
Exemplo n.º 29
0
        //[Route("MK_SCORE_PARTY/{agendaId}/orders")]
        public IHttpActionResult GetMK_SCORE_PARTY(int id)
        {
            var context = System.Web.HttpContext.Current;

            using (AgendaEntities db = new AgendaEntities())
            {
                //ImportBillVotesByAgenda(id);
                //AGENDA_DTO aGENDA_DTO = db.AGENDA_DTO.Find(id);
                //AGENDA_DTO aMK_SCORE_PARTY = null;
                List <MK_SCORE_PARTY> aMK_SCORE_PARTY = (from mk_s in db.MK_SCORE
                                                         join mk_p in db.MK_TO_PARTY on mk_s.mk equals mk_p.mk
                                                         where mk_s.agendaId == id
                                                         select new MK_SCORE_PARTY()
                {
                    IdMK_SCORE = mk_s.Id,
                    mk = mk_s.mk,
                    mkName = mk_s.MK1.mk_name,
                    party = mk_p.party,
                    partyName = mk_p.PARTY1.party1,
                    fromDate = mk_s.fromDate,
                    toDate = mk_s.toDate,
                    knessetNumber = mk_p.knessetNumber,
                    score = mk_s.score,
                    volume = mk_s.volume,
                    agendaId = mk_s.agendaId,
                    agendaName = mk_s.AGENDA.name
                }).ToList();

                if (aMK_SCORE_PARTY == null)
                {
                    ErrorLog.GetDefault(context).Log(new Error(new Exception(" GetMK_SCORE_PARTY(int id)-return NotFound")));
                    return(NotFound());
                }

                ErrorLog.GetDefault(context).Log(new Error(new Exception(" GetMK_SCORE_PARTY(int id)-return Ok(aMK_SCORE_PARTY)")));

                return(Ok(aMK_SCORE_PARTY));
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// Will add a record into the Database containing data that describes an agenda event
        /// </summary>
        /// <param name="name"></param>
        /// <param name="date"></param>
        /// <param name="time"></param>
        /// <param name="description"></param>
        public void AddRecordToDB(string name, DateTime date, DateTime time, string description)
        {
            try
            {
                using (var context = new AgendaEntities())
                {
                    var evnt = new Event()
                    {
                        Name        = name,
                        Date        = date,
                        Time        = time.TimeOfDay,
                        Description = description
                    };
                    context.Events.Add(evnt);

                    context.SaveChanges();
                }
            }catch (Exception e)
            {
                MessageBox.Show("Exception Details: " + e);
            }
        }