コード例 #1
0
        public static UserAffiliation inviteUser(User user, Company company, Role role, User granter)
        {
            if (user==null)
            {
                throw new ArgumentNullException("user");
            }
            else if (company==null)
            {
                throw new ArgumentNullException("company");
            }
            else if (role==null)
            {
                throw new ArgumentNullException("role");
            }
            else if (granter==null)
            {
                throw new ArgumentNullException("granter");
            }

            UserAffiliation affiliation = new UserAffiliation { acceptedByCompany = true, company = company, user = user, role = role, grantedByUser = granter };

            repo.Create(affiliation);

            if (affiliation.user.signedUp)
            {
                //Send normal invite
            }
            else
            {
                //Send invite to sign up
            }

            return affiliation;
        }
コード例 #2
0
        public static UserAffiliation UpdatePermission(UserAffiliation affiliation, User granter)
        {
            if (granter == null)
            {
                throw new ArgumentNullException("granter");
            }
            else if (affiliation == null)
            {
                throw new ArgumentNullException("affiliation");
            }

            UserAffiliation updAffiliation = repo.GetById(affiliation.id);

            if ((affiliation.company.id!=updAffiliation.company.id)||(affiliation.user.id!=updAffiliation.user.id))
            {
                throw new Exception("Object mismatch");
            }

            if (affiliation.role==null)
            {
                throw new Exception("New affiliation role is null!");
            }
            if (updAffiliation.role == null)
            {
                throw new Exception("Original affiliation role is null!");
            }

            if (affiliation.role.id==updAffiliation.role.id)
            {
                return updAffiliation;
            }

            if (!granter.affiliations.Any(o => o.company.id==updAffiliation.company.id && (o.role.name.Equals("Ejer")||o.role.name.Equals("Admin"))))
            {
                throw new NotAllowedException("User does not have permission to change affiliations");
            }

            if (affiliation.role.name.Equals("Ejer"))
            {
                throw new Exception("Owner can not be granted");
            }

            if (affiliation.role.name.Equals("Admin")&&(!granter.affiliations.Any(o => o.company.id==updAffiliation.company.id && o.role.name.Equals("Ejer"))))
            {
                throw new NotAllowedException("Only owners can grant admin");
            }

            updAffiliation.role = affiliation.role;

            repo.Update(updAffiliation);

            //Send notification to user

            return updAffiliation;
        }
コード例 #3
0
ファイル: CompanyManager.cs プロジェクト: KennethLauge/BizDoc
        public static Company updateCompany(Company c, User u)
        {
            //Check if user has permission to update company -- Remember to check for role
            if (!u.affiliations.Any(o => o.company.id==c.id))
            {
                throw new NotAllowedException("User does not have permission to update company");
            }

            new CompanyRepository().Update(c);

            return c;
        }
コード例 #4
0
ファイル: CompanyManager.cs プロジェクト: KennethLauge/BizDoc
        public static Company createCompany(Company c, User u)
        {
            new CompanyRepository().Create(c);

            UserAffiliation ua = new UserAffiliation { company = c, user = u, grantedByUser = u, role = new RoleRepository().GetByName("Ejer"), acceptedByCompany = true, acceptedByUser = true };

            AffiliationManager.setAsPrimary(ua);

            new UserAffiliationRepository().Create(ua);

            return c;
        }
コード例 #5
0
ファイル: UserManager.cs プロジェクト: KennethLauge/BizDoc
        public static User createUserFromInvite(string email, bool signature)
        {
            User user = new User();

            UserEmail userEmail = new UserEmail { email = email, user = user, inUse = true };

            repo.Create(user);
            new UserEmailRepository().Create(userEmail);

            //Create notification
            NotificationManager.create(user, "Velkommen til BizDoc, kom i gang med at redigere dine brugeroplysninger.", "/Bruger/Indstillinger#/Bruger/Stamoplysninger");

            return user;
        }
コード例 #6
0
ファイル: UserManager.cs プロジェクト: KennethLauge/BizDoc
        public static User updateUser(User u, User currentUser)
        {
            //Check if user has permission to update user
            if (currentUser.id!=u.id)
            {
                throw new NotAllowedException("User does not have permission to update user info");
            }

            currentUser.firstName = u.firstName;
            currentUser.lastName = u.lastName;
            currentUser.cpr = u.cpr;

            new UserRepository().Update(currentUser);

            return u;
        }
コード例 #7
0
ファイル: UserManager.cs プロジェクト: KennethLauge/BizDoc
        public static User createUser(string email, string password)
        {
            User user = new User();
            user.setPassword(password);
            user.signedUp = true;

            UserEmail userEmail = new UserEmail { email = email, user = user, inUse = true };

            repo.Create(user);
            new UserEmailRepository().Create(userEmail);

            //Create notification
            NotificationManager.create(user, "Velkommen til BizDoc, kom i gang med at redigere dine brugeroplysninger.", "/Bruger/Indstillinger#/Bruger/Stamoplysninger");

            return user;
        }
コード例 #8
0
ファイル: CompanyManager.cs プロジェクト: KennethLauge/BizDoc
        public static Company createCompany(string cvr, User u)
        {
            Company c = new Company();

            c.cvr = cvr;
            c.name = "test"; //CHANGE!!!!

            new CompanyRepository().Create(c);

            UserAffiliation ua = new UserAffiliation { company = c, user = u, grantedByUser = u, role = new RoleRepository().GetByName("Ejer"), acceptedByCompany = true, acceptedByUser = true };

            if (!u.affiliations.Any(x => x.isPrimary))
            {
                AffiliationManager.setAsPrimary(ua);
            }
            new UserAffiliationRepository().Create(ua);

            return c;
        }
コード例 #9
0
 public ActionResult Stamoplysninger(User model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var response = HttpClientFactory.getClient(this.ControllerContext).PutAsJsonAsync("user/update/" + model.id, model).Result;
             if (response.IsSuccessStatusCode)
             {
                 // Parse the response body. Blocking!
                 var user = response.Content.ReadAsAsync<User>().Result;
                 ViewBag.updated = true;
                 return PartialView(user);
             }
             else if (response.StatusCode == HttpStatusCode.Forbidden)
             {
                 return RedirectToAction("IkkeAdgang", "Bruger");
             }
             else
             {
                 ViewBag.updated = false;
                 return PartialView(response.Content.ReadAsAsync<User>().Result);
             }
         }
         else
         {
             ViewBag.updated = false;
             return PartialView(model);
         }
     }
     catch (Exception e)
     {
         throw new Exception("Could not update user", e);
     }
 }
コード例 #10
0
ファイル: UserTicket.cs プロジェクト: KennethLauge/BizDoc
 public UserTicket(User user)
 {
     this.start = DateTime.Now;
     this.end = DateTime.Now.AddDays(days);
     this.user = user;
 }