コード例 #1
0
 public bool Hash(LoginRequest credentials)
 {
     using (Context = new ProjectLineContext())
     {
         try
         {
             var equal = true;
             /* Fetch the stored value */
             //string savedPasswordHash = Context.Users.Where(u => u.Email == credentials.Email).Select(u => u.Password).First();
             string savedPasswordHash = Context.Users.Where(u => u.Email == credentials.Email && u.Active == true).Select(u => u.Password).First();
             /* Extract the bytes */
             byte[] hashBytes = Convert.FromBase64String(savedPasswordHash);
             /* Get the salt */
             byte[] salt = new byte[16];
             Array.Copy(hashBytes, 0, salt, 0, 16);
             /* Compute the hash on the password the user entered */
             var    pbkdf2 = new Rfc2898DeriveBytes(credentials.Password, salt, 10000);
             byte[] hash   = pbkdf2.GetBytes(20);
             /* Compare the results */
             for (int i = 0; i < 20; i++)
             {
                 if (hashBytes[i + 16] != hash[i])
                 {
                     equal = false;
                 }
             }
             return(equal);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
コード例 #2
0
        private void AddOrUpdatePhases(Project project, int id, ProjectLineContext context)
        {
            foreach (var phase in project.Phases)
            {
                phase.ProjectID = id;
                if (phase.DemoName == null || phase.DemoName.Equals(""))
                {
                    phase.DemoUrl = "";
                }
                else if (phase.DemoVideo != null)
                {
                    phase.DemoUrl = "/assets/Demo/" + phase.Title + "_" + phase.DemoName;
                    SaveDemo(phase.DemoVideo, phase.DemoUrl);
                }

                if (phase.PhaseID == 0)
                {
                    phaseRepository.Create(phase, context);
                }
                else
                {
                    phaseRepository.Update(phase, context);
                }
            }
        }
コード例 #3
0
 public bool ValidateEmailUnique(string email, int id)
 {
     using (Context = new ProjectLineContext())
     {
         var existEmail = Context.Users.Where(x => x.Email == email && x.UserID != id).Count();
         return(existEmail > 0);
     }
 }
コード例 #4
0
 public Project FindById(int id)
 {
     using (Context = new ProjectLineContext())
     {
         var result = Context.Projects.Include("Phases").Where(s => s.ProjectID == id).FirstOrDefaultAsync();
         return(result.Result);
     }
 }
コード例 #5
0
 public Objective FindById(int id)
 {
     using (Context = new ProjectLineContext())
     {
         var result = Context.Objectives.Where(s => s.ObjectiveID == id).FirstOrDefaultAsync();
         return(result.Result);
     }
 }
コード例 #6
0
 public User FindByEmail(string email)
 {
     using (Context = new ProjectLineContext())
     {
         var result = Context.Users.Where(s => s.Email == email).FirstOrDefaultAsync();
         result.Result.Password = "";
         return(result.Result);
     }
 }
コード例 #7
0
        public async Task <IEnumerable <User> > GetUserPO(int id)
        {
            using (Context = new ProjectLineContext())
            {
                var result = await Context.Users.Include("Role").Where(x => x.UserID == id).ToListAsync();

                return(result);
            }
        }
コード例 #8
0
        public async Task <IEnumerable <Project> > GetProjects()
        {
            using (Context = new ProjectLineContext())
            {
                var result = await Context.Projects.Include("User").Include("Phases").Include("Phases.Objectives").Where(x => x.Active == true).ToListAsync();

                return(result);
            }
        }
コード例 #9
0
        public async Task <IEnumerable <Project> > GetProjectsCL(int id)
        {
            using (Context = new ProjectLineContext())
            {
                var result = await Context.Projects.Include("User").Include("Phases").Include("Phases.Objectives").Where(x => x.Active == true && x.UserID == id).OrderByDescending(x => x.ProjectID).ToListAsync();

                return(result);
            }
        }
コード例 #10
0
        public async Task <IEnumerable <Phase> > GetPhases()
        {
            using (Context = new ProjectLineContext())
            {
                var result = await Context.Phases.Take(100).ToListAsync();

                return(result);
            }
        }
コード例 #11
0
        public async Task <IEnumerable <Objective> > GetObjectives(int id)
        {
            using (Context = new ProjectLineContext())
            {
                var result = await Context.Objectives.Where(x => x.PhaseID == id).ToListAsync();

                return(result);
            }
        }
コード例 #12
0
        public async Task <IEnumerable <Project> > GetArchivedProjectsPO(int id)
        {
            using (Context = new ProjectLineContext())
            {
                var result = await Context.Projects.Include("User").Include("Phases").Include("Phases.Objectives").Where(x => x.Active == false && x.OwnerID == id).ToListAsync();

                return(result);
            }
        }
コード例 #13
0
        public async Task <IEnumerable <Role> > GetRoles()
        {
            using (Context = new ProjectLineContext())
            {
                var result = await Context.Roles.ToListAsync();

                return(result);
            }
        }
コード例 #14
0
 public void Create(Phase phase, ProjectLineContext context)
 {
     try
     {
         context.Phases.Add(phase);
         context.SaveChanges();
     }
     catch (Exception ex)
     {
         Console.Write(ex);
     }
 }
コード例 #15
0
        public void Delete(int id, ProjectLineContext context)
        {
            try
            {
                var phaseDelete = FindById(id, context);

                context.Phases.Remove(phaseDelete);
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                Console.Write(ex);
            }
        }
コード例 #16
0
 public void Create(PermissionRole PermissionRole)
 {
     try
     {
         using (Context = new ProjectLineContext())
         {
             Context.PermissionsRoles.Add(PermissionRole);
             Context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         Console.Write(ex);
     }
 }
コード例 #17
0
        public async Task <IEnumerable <User> > GetUsersByRol(int id)
        {
            using (Context = new ProjectLineContext())
            {
                var listusers = await Context.Users.Include("Role").Where(x => x.Role.RoleID == id).ToListAsync();

                var result = listusers.Select(u => new User()
                {
                    UserID    = u.UserID,
                    FirstName = u.FirstName,
                    LastName  = u.LastName
                });
                return(result);
            }
        }
コード例 #18
0
 public void Create(Phase phase)
 {
     try
     {
         using (Context = new ProjectLineContext())
         {
             Context.Phases.Add(phase);
             Context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         Console.Write(ex);
     }
 }
コード例 #19
0
 public string LoginAuthentication(LoginRequest credentials)
 {
     using (Context = new ProjectLineContext())
     {
         try
         {
             User user = Context.Users.Where(u => u.Email == credentials.Email).First();
             return(Hash(credentials) ? TokenGenerator.GenerateTokenJwt(credentials.Email, user) : "");
         }
         catch (Exception)
         {
             return("");
         }
     }
 }
コード例 #20
0
 public void Create(Objective objective)
 {
     try
     {
         using (Context = new ProjectLineContext())
         {
             Context.Objectives.Add(objective);
             Context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         Console.Write(ex);
     }
 }
コード例 #21
0
 public void Create(Role rol)
 {
     try
     {
         using (Context = new ProjectLineContext())
         {
             Context.Roles.Add(rol);
             Context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         Console.Write(ex);
     }
 }
コード例 #22
0
 public void Delete(int id)
 {
     try
     {
         var phaseDelete = FindById(id);
         using (var Context = new ProjectLineContext())
         {
             Context.Phases.Remove(phaseDelete);
             Context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         Console.Write(ex);
     }
 }
コード例 #23
0
 public void Delete(int id)
 {
     try
     {
         var delete = FindById(id);
         using (Context = new ProjectLineContext())
         {
             Context.Objectives.Attach(delete);
             Context.Objectives.Remove(delete);
             Context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         Console.Write(ex);
     }
 }
コード例 #24
0
 public void DeletePasive(int id)
 {
     try
     {
         var StatusUpdate = FindById(id);
         using (Context = new ProjectLineContext())
         {
             // StatusUpdate.StatusID = 0;
             StatusUpdate.Active = false;
             Context.Entry(StatusUpdate).State = EntityState.Modified;
             Context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         Console.Write(ex);
     }
 }
コード例 #25
0
        public void Create(User User)
        {
            try
            {
                using (Context = new ProjectLineContext())
                {
                    User.Password = HashPassword(User.Password);


                    Context.Users.Add(User);
                    Context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex);
            }
        }
コード例 #26
0
        public void Update(User User)
        {
            try
            {
                var update = FindById(User.UserID);
                using (Context = new ProjectLineContext())
                {
                    if (User.Password == "")
                    {
                        update.FirstName = User.FirstName;
                        update.LastName  = User.LastName;
                        update.Email     = User.Email;
                        update.Company   = User.Company;
                        update.Address   = User.Address;
                        update.Phone     = User.Phone;
                        update.Mobile    = User.Mobile;
                        update.Active    = User.Active;
                        update.RoleID    = User.RoleID;
                    }
                    else
                    {
                        update.FirstName = User.FirstName;
                        update.LastName  = User.LastName;
                        update.Email     = User.Email;
                        update.Company   = User.Company;
                        update.Address   = User.Address;
                        update.Phone     = User.Phone;
                        update.Mobile    = User.Mobile;
                        update.Password  = HashPassword(User.Password);
                        update.Active    = User.Active;
                        update.RoleID    = User.RoleID;
                    }

                    Context.Entry(update).State = EntityState.Modified;
                    Context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex);
            }
        }
コード例 #27
0
        public IEnumerable <Permission> GetPermissionsByRole(int id)
        {
            try
            {
                using (Context = new ProjectLineContext())
                {
                    var result = from p in Context.Permissions
                                 join pr in Context.PermissionsRoles on p.PermissionID equals pr.PermissionID
                                 join r in Context.Roles on pr.RoleID equals r.RoleID
                                 where r.RoleID == id
                                 select p;

                    return(result.ToList());
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #28
0
        public void Update(Role rol)
        {
            try
            {
                var update = FindById(rol.RoleID);
                using (Context = new ProjectLineContext())
                {
                    //update.Title = rol.Title;
                    update.Description = rol.Description;


                    Context.Entry(update).State = EntityState.Modified;
                    Context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex);
            }
        }
コード例 #29
0
        public void Update(Phase phase, ProjectLineContext context)
        {
            try
            {
                var update = FindById(phase.PhaseID, context);
                update.Title       = phase.Title;
                update.Description = phase.Description;
                update.StartDate   = phase.StartDate;
                update.EndDate     = phase.EndDate;
                update.DemoUrl     = phase.DemoUrl;
                update.DemoName    = phase.DemoName;

                context.Entry(update).State = EntityState.Modified;
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                Console.Write(ex);
            }
        }
コード例 #30
0
        public void Update(Project project)
        {
            try
            {
                var context = new ProjectLineContext();
                using (var Trans = context.Database.BeginTransaction())
                {
                    try
                    {
                        //Get Project of the DB
                        var update = FindById(project.ProjectID);
                        DeletePhasesExistens(update, project, context);

                        //Update Project Data
                        update.Title       = project.Title;
                        update.Description = project.Description;
                        update.StartDate   = project.StartDate;
                        update.EndDate     = project.EndDate;
                        update.UserID      = project.UserID;
                        update.OwnerID     = project.OwnerID;

                        context.Entry(update).State = EntityState.Modified;
                        context.SaveChanges();

                        AddOrUpdatePhases(project, update.ProjectID, context);

                        Trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        Console.Write(ex);
                        Trans.Rollback();
                    }
                }
                context.Dispose();
            }
            catch (Exception ex)
            {
                Console.Write(ex);
            }
        }