示例#1
0
        public static void Create(int projectId, string[] selection)
        {
            using (var db = new ViolaContext())
            {
                // mevcut iliþkiler silinir.
                foreach (var row in db.ProjectTeams.Where(x => x.ProjectId == projectId))
                {
                    db.ProjectTeams.Remove(row);
                }

                // yeni iliþkiler kaydedilir
                if (selection != null)
                {
                    foreach (var id in selection)
                    {
                        var row = new ProjectTeam
                        {
                            ProjectId = projectId,
                            UserId    = id
                        };
                        row.InitCreateValue();

                        db.ProjectTeams.Add(row);
                    }
                }

                db.SaveChanges();
            }
        }
示例#2
0
        public static void Create(int _taskId, string[] selection)
        {
            using (var db = new ViolaContext())
            {
                // mevcut iliþkiler silinir.
                foreach (var row in db.TaskAssignedUsers.Where(x => x.TaskId == _taskId))
                {
                    db.TaskAssignedUsers.Remove(row);
                }

                // yeni iliþkiler kaydedilir
                if (selection != null)
                {
                    foreach (var id in selection)
                    {
                        var row = new TaskAssignedUser
                        {
                            TaskId = _taskId,
                            UserId = id
                        };
                        row.InitCreateValue();

                        // eðer projeye ekibinde yer alan bir kullanýcý ise task ile iliþkilendirilir.
                        if (Viola.Models.User.GetUsersAssignedToProject(Task.Find(_taskId).ProjectId).Where(x => x.Id == row.UserId).Any())
                        {
                            db.TaskAssignedUsers.Add(row);
                        }
                    }
                }

                db.SaveChanges();
            }
        }
示例#3
0
        public static IQueryable <User> GetUsers()
        {
            var db      = new ViolaContext();
            var curUser = Viola.Models.User.GetCurrentUser();

            return(db.Users.Where(x => x.CompanyId == curUser.CompanyId).OrderBy(x => x.FullName));
        }
示例#4
0
        public static IQueryable <Project> GetProjectsByRole()
        {
            IQueryable <Project> ret;
            var db      = new ViolaContext();
            var curUser = Viola.Models.User.GetCurrentUser();

            // bütün projeler
            if (curUser.UserRole == UserRole.Admin)
            {
                ret = db.Projects.Where(x => x.CompanyId == curUser.CompanyId);
            }
            // user kendi oluþturduðu ve atandýðý projeleri görebilir
            else
            {
                ret = from p in db.Projects

                      // mevcut kullanýcý proje ekibinde yer alýyormu kontrol et
                      let pt = from pt in db.ProjectTeams
                               where pt.ProjectId == p.Id && pt.UserId == curUser.Id
                               select pt.UserId

                               where p.CompanyId == curUser.CompanyId &&
                               (p.CreatedUserId == curUser.Id ||
                                pt.Contains(curUser.Id))
                               orderby p.Name
                               select p;
            }

            return(ret);
        }
示例#5
0
        public static IQueryable <Task> GetTasksByRole()
        {
            IQueryable <Task> ret;
            var db      = new ViolaContext();
            var curUser = Viola.Models.User.GetCurrentUser();

            // bütün tasklar
            if (curUser.UserRole == UserRole.Admin)
            {
                ret = db.Tasks.Where(x => x.CompanyId == curUser.CompanyId);
            }
            // user kendi oluþturduðu ve atandýðý projelere ait tasklarý görebilir
            else
            {
                ret = from p in db.Projects
                      join t in db.Tasks on p.Id equals t.ProjectId

                      // mevcut kullanýcý proje ekibinde yer alýyormu kontrol et
                      let pt = from pt in db.ProjectTeams
                               where pt.ProjectId == p.Id && pt.UserId == curUser.Id
                               select pt.UserId

                               where p.CompanyId == curUser.CompanyId &&
                               (p.CreatedUserId == curUser.Id ||
                                pt.Contains(curUser.Id))
                               orderby t.Id descending
                               select t;
            }

            return(ret);
        }
示例#6
0
        public static IQueryable <Task> GetTasksByProjectId(int projectId)
        {
            var db      = new ViolaContext();
            var curUser = Viola.Models.User.GetCurrentUser();

            return(from t in db.Tasks
                   where t.CompanyId == curUser.CompanyId &&
                   t.ProjectId == projectId
                   orderby t.Name
                   select t);
        }
示例#7
0
        public static User GetUser(string userId, ViolaContext context = null)
        {
            if (context == null)
            {
                context = new ViolaContext();
            }

            var userManager = new UserManager <User>(new UserStore <User>(context));

            return(userManager.FindById(userId));
        }
示例#8
0
        public static IQueryable <User> GetUsersAssignedToProject(int projectId)
        {
            var db      = new ViolaContext();
            var curUser = Viola.Models.User.GetCurrentUser();

            return(from pt in db.ProjectTeams
                   join u in db.Users on pt.UserId equals u.Id
                   where u.CompanyId == curUser.CompanyId &&
                   pt.ProjectId == projectId
                   orderby u.FullName
                   select u);
        }
示例#9
0
        public static decimal SumSizeByTransDate(DateTime datetime)
        {
            var    db        = new ViolaContext();
            string curUserId = Viola.Models.User.GetCurrentUserId();

            var result = from e in db.Efforts
                         where e.UserId == curUserId &&
                         e.TransDate == datetime
                         select e;

            return(result.AsEnumerable().Sum(o => o.Size));
        }
示例#10
0
        public UsersController()
        {
            context     = new ViolaContext();
            UserManager = new UserManager <User>(new UserStore <User>(context));
            RoleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));

            // email adresinin userName olarak kaydedilmesi için
            UserManager.UserValidator = new UserValidator <User>(UserManager)
            {
                AllowOnlyAlphanumericUserNames = false
            };
        }
示例#11
0
        public static IQueryable <User> GetUsersForEffort()
        {
            var db      = new ViolaContext();
            var curUser = Viola.Models.User.GetCurrentUser();

            if (curUser.UserRole == UserRole.Admin)
            {
                return(GetUsers());
            }
            else
            {
                return(GetUsers().Where(x => x.Id == curUser.Id));
            }
        }
示例#12
0
        public static List <string> UserIdSelection(int projectId)
        {
            var ret = new List <string>();

            using (var db = new ViolaContext())
            {
                var rows = db.ProjectTeams.Where(x => x.ProjectId == projectId);
                foreach (var row in rows)
                {
                    ret.Add(row.UserId);
                }
            }

            return(ret);
        }
示例#13
0
        public static List <string> UserIdSelection(int _projectId)
        {
            var ret = new List <string>();

            using (var db = new ViolaContext())
            {
                var rows = db.TaskAssignedUsers.Where(x => x.TaskId == _projectId);
                foreach (var row in rows)
                {
                    ret.Add(row.UserId);
                }
            }

            return(ret);
        }
示例#14
0
        public static void AddProjectManagerToTeam(Project project)
        {
            var db = new ViolaContext();

            if (!ProjectTeam.Exist(project.Id, project.ManagerUserId))
            {
                var pt = new ProjectTeam()
                {
                    ProjectId = project.Id,
                    UserId    = project.ManagerUserId
                };

                pt.InitCreateValue();

                db.ProjectTeams.Add(pt);
                db.SaveChanges();
            }
        }
示例#15
0
        public static IQueryable <Effort> GetEffortsByRole()
        {
            IQueryable <Effort> ret;
            var db      = new ViolaContext();
            var curUser = Viola.Models.User.GetCurrentUser();

            // bütün eforlar
            if (curUser.UserRole == UserRole.Admin)
            {
                return(db.Efforts.Where(x => x.CompanyId == curUser.CompanyId).OrderByDescending(x => x.TransDate));
            }
            // user kendi girdiði eforlarý görür
            else
            {
                ret = from e in db.Efforts
                      where e.CompanyId == curUser.CompanyId &&
                      e.UserId == curUser.Id
                      orderby e.TransDate descending
                      select e;
            }

            return(ret);
        }
示例#16
0
 public static Company GetCurrentCompany(ViolaContext context = null)
 {
     return(User.GetCurrentUser(context).Company);
 }
示例#17
0
        public static bool Exist(int taskId, string userId)
        {
            var db = new ViolaContext();

            return(db.TaskAssignedUsers.Where(x => x.TaskId == taskId && x.UserId == userId).Any());
        }
示例#18
0
        public static bool Exist(int projectId, string userId)
        {
            var db = new ViolaContext();

            return(db.ProjectTeams.Where(x => x.ProjectId == projectId && x.UserId == userId).Any());
        }
示例#19
0
        public static Task Find(int taskId)
        {
            var db = new ViolaContext();

            return(db.Tasks.Where(x => x.Id == taskId).FirstOrDefault());
        }
示例#20
0
 public static User GetCurrentUser(ViolaContext context = null)
 {
     return(GetUser(GetCurrentUserId(), context));
 }