Example #1
0
        public List <IPropertieQueryDTO> ListPropertie()
        {
            List <IPropertieQueryDTO> result = new List <IPropertieQueryDTO>();

            using (RealPageDBContext context = new RealPageDBContext())
            {
                try
                {
                    result = (from p in context.Properties
                              select new PropertieQuery()
                    {
                        IdPropertie = p.IdPropertie,
                        Name = p.Name,
                        Location = p.Location,
                        Price = p.Price,
                        IdUser = p.IdUser
                    }).ToList <IPropertieQueryDTO>();
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }
            return(result);
        }
Example #2
0
        public bool EditPropertie(IPropertieDTO propertie)
        {
            bool result = false;

            using (RealPageDBContext context = new RealPageDBContext())
            {
                using (var transation = context.Database.BeginTransaction())
                {
                    try
                    {
                        Propertie editPropertie = context.Properties.Find(propertie.IdPropertie);
                        editPropertie = propertie.MapeadorPropertie <Propertie>(editPropertie);
                        context.Properties.Update(editPropertie);
                        context.SaveChanges();
                        transation.Commit();
                        result = true;
                    }
                    catch (Exception ex)
                    {
                        transation.Rollback();
                        throw new Exception(ex.Message);
                    }
                }
            }
            return(result);
        }
Example #3
0
        public List <IUserQueryDTO> ListUser()
        {
            List <IUserQueryDTO> result = new List <IUserQueryDTO>();

            using (RealPageDBContext context = new RealPageDBContext())
            {
                try
                {
                    result = (from u in context.Users
                              select new UserQuery()
                    {
                        IdUser = u.IdUser,
                        FirstName = u.FirstName,
                        LastName = u.LastName,
                        Adress = u.Adress,
                        Phone = u.Phone,
                        Email = u.Email,
                        Active = u.Active
                    }).ToList <IUserQueryDTO>();
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }
            return(result);
        }
Example #4
0
        public bool DeletePropertie(int id)
        {
            bool result = false;

            using (RealPageDBContext context = new RealPageDBContext())
            {
                using (var transation = context.Database.BeginTransaction())
                {
                    try
                    {
                        Propertie deletePropertie = context.Properties.Find(id);
                        context.Properties.Remove(deletePropertie);
                        context.SaveChanges();
                        transation.Commit();
                        result = true;
                    }
                    catch (Exception ex)
                    {
                        transation.Rollback();
                        throw new Exception(ex.Message);
                    }
                }
            }
            return(result);
        }
Example #5
0
        public bool EditUser(IUserDTO user)
        {
            bool result = false;

            using (RealPageDBContext context = new RealPageDBContext())
            {
                using (var transation = context.Database.BeginTransaction())
                {
                    try
                    {
                        User editUser = context.Users.Find(user.IdUser);
                        editUser = user.MapeadorUser <User>(editUser);
                        context.Users.Update(editUser);
                        context.SaveChanges();
                        transation.Commit();
                        result = true;
                    }
                    catch (Exception ex)
                    {
                        transation.Rollback();
                        throw new Exception(ex.Message);
                    }
                }
            }
            return(result);
        }