コード例 #1
0
 public UserContext(User user)
 {
     this.TenantId = user.TenantId;
     this.UserId = user.UserId;
     this.Username = user.Username;
     this.Password = user.Password;
     this.Role = user.Role.Title;
 }
コード例 #2
0
ファイル: UserBC.cs プロジェクト: AmartyaPal/IIHT_GIT
 public int UpdateUserDetails(MODEL.User user)
 {
     using (dbContext)
     {
         var editDetails = (from record in dbContext.Users
                            where record.User_ID == user.UserId
                            select record).First();
         if (editDetails != null)
         {
             editDetails.First_Name  = user.FirstName;
             editDetails.Last_Name   = user.LastName;
             editDetails.Employee_ID = user.EmployeeId;
         }
         return(dbContext.SaveChanges());
     }
 }
コード例 #3
0
 public int UpdateUserDetails(MODEL.User user)
 {
     using (_projectManagerCtx)
     {
         var editDetails = (from editUser in _projectManagerCtx.Users
                            where editUser.User_ID == user.UserId
                            select editUser).First();
         // Modify existing records
         if (editDetails != null)
         {
             editDetails.First_Name  = user.FirstName;
             editDetails.Last_Name   = user.LastName;
             editDetails.Employee_ID = user.EmployeeId;
         }
         return(_projectManagerCtx.SaveChanges());
     }
 }
コード例 #4
0
        public void TestDeleteUser_Success()
        {
            var context = new MockProjectManagerEntities();
            var users   = new TestDbSet <ProjectManager.DAC.User>();

            users.Add(new ProjectManager.DAC.User()
            {
                Employee_ID = "592561",
                First_Name  = "narayan",
                Last_Name   = "dubey",
                Project_ID  = 123,
                Task_ID     = 123,
                User_ID     = 592561
            });
            users.Add(new ProjectManager.DAC.User()
            {
                Employee_ID = "493210",
                First_Name  = "Prasun",
                Last_Name   = "sarkar",
                Project_ID  = 1234,
                Task_ID     = 1234,
                User_ID     = 493210
            });
            context.Users = users;

            var user = new ProjectManager.Models.User();

            user.FirstName  = "Prasun";
            user.LastName   = "sarkar";
            user.EmployeeId = "493210";
            user.UserId     = 493210;

            var controller = new UserController(new ProjectManager.BC.UserBC(context));
            var result     = controller.DeleteUserDetails(user) as JSonResponse;

            Assert.IsNotNull(result);
            Assert.AreEqual(context.Users.Local.Count, 1);
        }
コード例 #5
0
        public void TestDeleteUser_Success(BenchmarkContext benchContext)
        {
            var context = new MockProjectManagerEntities();
            var users   = new TestDbSet <DAC.User>();

            users.Add(new DAC.User()
            {
                Employee_ID = "418220",
                First_Name  = "Sweta",
                Last_Name   = "Misra",
                Project_ID  = 123,
                Task_ID     = 123,
                User_ID     = 418220
            });
            users.Add(new DAC.User()
            {
                Employee_ID = "503322",
                First_Name  = "ABC",
                Last_Name   = "XYZ",
                Project_ID  = 1234,
                Task_ID     = 1234,
                User_ID     = 503322
            });
            context.Users = users;

            var user = new ProjectManager.Models.User();

            user.FirstName  = "ABC";
            user.LastName   = "XYZ";
            user.EmployeeId = "503322";
            user.UserId     = 503322;

            var controller = new UserController(new BC.UserBC(context));
            var result     = controller.DeleteUserDetails(user) as JSendResponse;

            addCounter.Increment();
        }
コード例 #6
0
 public int AddUserDetails(MODEL.User user)
 {
     if (user == null)
     {
         throw new ArgumentNullException("User id is null");
     }
     try
     {
         int employeeId = Convert.ToInt32(user.EmployeeId);
     }
     catch (FormatException ex)
     {
         throw new FormatException("Invalid format of employee Id", ex);
     }
     if (Convert.ToInt32(user.EmployeeId) < 0)
     {
         throw new ArithmeticException("Employee id cannot be negative");
     }
     if (Convert.ToInt32(user.ProjectId) < 0)
     {
         throw new ArithmeticException("Project id cannot be negative");
     }
     return(userDAC.InsertUserDetails(user));
 }
コード例 #7
0
        public ActionResult Create(NewTenantContext newTenant, HttpPostedFileBase file)
        {
            if (string.IsNullOrWhiteSpace(newTenant.OrgName) || string.IsNullOrWhiteSpace(newTenant.AdminUsername) ||
                string.IsNullOrWhiteSpace(newTenant.AdminPassword) || string.IsNullOrWhiteSpace(newTenant.ConfirmPassword))
            {
                return View();
            }

            if (newTenant.AdminPassword != newTenant.ConfirmPassword)
            {
                return View();
            }

            bool success = false;
            using (var db = new DataClassesDataContext())
            {
                var numMatched = db.Tenants.Where(t => t.OrgName == newTenant.OrgName).Count();
                numMatched += db.Users.Where(u => u.Username == newTenant.AdminUsername).Count();

                if (numMatched == 0)
                {
                    Tenant tenant = new Tenant();
                    tenant.OrgName = newTenant.OrgName;
                    tenant.LogoPath = "/Logos/logo1.jpg";
                    tenant.BannerColor = OnlyHexInString(newTenant.BannerColor) ? newTenant.BannerColor : "#357ebd";
                    tenant.TextColor = OnlyHexInString(newTenant.TextColor) ? newTenant.TextColor : "#FFFFFF";
                    tenant.CustomTypes = newTenant.CustomTypes;

                    User user = new User();
                    user.Username = newTenant.AdminUsername;
                    user.Password = Auth.GetPasswordHash(newTenant.AdminPassword);
                    user.RoleId = 1;

                    tenant.Users.Insert(tenant.Users.Count, user);

                    db.Tenants.InsertOnSubmit(tenant);
                    db.SubmitChanges();

                    if (file != null && file.ContentLength > 0)
                    {
                        // store the file inside ~/Logos/uploads folder. Name it Org Name of the tenant
                        string fileName = string.Format("{0}{1}", tenant.TenantId, Path.GetExtension(file.FileName));
                        string path = Path.Combine(Server.MapPath("~/Logos"), fileName);
                        file.SaveAs(path);
                        tenant.LogoPath = "/Logos/" + fileName;
                        db.SubmitChanges();
                    }

                    success = true;

                    Auth.Login(user);
                }
            }

            if (!success)
            {
                // need to add error message
                return RedirectToAction("Create");
            }

            return RedirectToAction("Index", "Admin");
        }
コード例 #8
0
        public static void Login(User user)
        {
            CurrentUserContext currentUser = new CurrentUserContext();
            currentUser.TenantId = user.TenantId;
            currentUser.UserId = user.UserId;
            currentUser.Username = user.Username;
            currentUser.IsAdmin = (user.RoleId == 1);
            currentUser.IsManager = (user.RoleId == 4);

            using (var db = new DataClassesDataContext())
            {
                Tenant tenant = (from t in db.Tenants
                                 where t.TenantId == currentUser.TenantId
                                 select t).FirstOrDefault();

                currentUser.BannerColor = tenant.BannerColor;
                currentUser.TextColor = tenant.TextColor;
                currentUser.TenantName = tenant.OrgName;
                currentUser.LogoPath = tenant.LogoPath;
                currentUser.UsingCustomTypes = tenant.CustomTypes;
            }

            HttpContext.Current.Session["CurrentUser"] = currentUser;

            HttpCookie userCookie = new HttpCookie("ProjectManagerUserSession");
            userCookie["username"] = user.Username;
            userCookie["password"] = user.Password;
        }
コード例 #9
0
        public ActionResult Create(User newUser)
        {
            if (!Auth.IsLoggedIn())
            {
                return RedirectToAction("Login", "Home");
            }
            if (!Auth.GetCurrentUser().IsAdmin)
            {
                return RedirectToAction("Index");
            }

            if (string.IsNullOrWhiteSpace(newUser.Username) || string.IsNullOrWhiteSpace(newUser.Password))
            {
                return RedirectToAction("Create");
            }

            using (var db = new DataClassesDataContext())
            {
                var existingUser = (from u in db.Users
                                    where u.Username == newUser.Username
                                    select u).FirstOrDefault();

                if (existingUser == null)
                {
                    User user = new User();
                    user.TenantId = Auth.GetCurrentUser().TenantId;
                    user.Username = newUser.Username;
                    user.Password = Auth.GetPasswordHash(newUser.Password);
                    user.RoleId = newUser.RoleId > 0 ? newUser.RoleId : 5;    // default to GLOBAL.Employee for now

                    user.Role = (from r in db.Roles
                                 where r.RoleId == user.RoleId
                                 select r).FirstOrDefault();

                    db.Users.InsertOnSubmit(user);
                    db.SubmitChanges();
                }
            }

            return RedirectToAction("Index");
        }
コード例 #10
0
        public ActionResult Edit(User userToModify)
        {
            if (!Auth.IsLoggedIn())
            {
                return RedirectToAction("Login", "Home");
            }
            if (!Auth.GetCurrentUser().IsAdmin)
            {
                return RedirectToAction("Index");
            }

            using (var db = new DataClassesDataContext())
            {
                var user = (from u in db.Users
                            where u.UserId == userToModify.UserId
                            select u).FirstOrDefault();

                if (userToModify.Username != null)
                    user.Username = userToModify.Username;
                if (userToModify.RoleId > 0)
                    user.RoleId = userToModify.RoleId;

                db.SubmitChanges();

            }
            return RedirectToAction("Index");
        }
コード例 #11
0
 partial void DeleteUser(User instance);
コード例 #12
0
 partial void UpdateUser(User instance);
コード例 #13
0
 partial void InsertUser(User instance);
コード例 #14
0
		private void detach_Users(User entity)
		{
			this.SendPropertyChanging();
			entity.Tenant = null;
		}
コード例 #15
0
		private void attach_Users(User entity)
		{
			this.SendPropertyChanging();
			entity.Tenant = this;
		}