示例#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 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;
        }
示例#3
0
        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;
        }
示例#4
0
        public HttpResponseMessage Create(Company company)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            UserTicket ticket = TicketManager.getTicketFromContext(this.ControllerContext);

            Company newCompany = CompanyManager.createCompany(company, ticket.user);

            var response = Request.CreateResponse<Company>(HttpStatusCode.Created, newCompany);
            return response;
        }
示例#5
0
        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;
        }
 public ActionResult Stamoplysninger(Company model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var response = HttpClientFactory.getClient(this.ControllerContext).PutAsJsonAsync("company/update/" + model.id, model).Result;
             if (response.IsSuccessStatusCode)
             {
                 // Parse the response body. Blocking!
                 var company = response.Content.ReadAsAsync<Company>().Result;
                 ViewBag.updated = true;
                 return PartialView(company);
             }
             else if (response.StatusCode == HttpStatusCode.Forbidden)
             {
                 return RedirectToAction("IkkeAdgang", "Bruger");
             }
             else
             {
                 ViewBag.updated = false;
                 return PartialView(response.Content.ReadAsAsync<Company>().Result);
             }
         }
         else
         {
             ViewBag.updated = false;
             return PartialView(model);
         }
     }
     catch (Exception e)
     {
         throw new Exception("Could not update company", e);
     }
 }
        public ActionResult Opret(Company model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var response = HttpClientFactory.getClient(this.ControllerContext).PostAsJsonAsync("company/create/", model).Result;
                    if (response.IsSuccessStatusCode)
                    {
                        // Parse the response body. Blocking!
                        var company = response.Content.ReadAsAsync<Company>().Result;

                        return RedirectToAction("Forside", "Hjem");
                    }
                    else
                    {
                        return View(response.Content.ReadAsAsync<Company>().Result);
                    }
                }
                else
                {
                    return View(model);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Could not create company", e);
            }
        }
示例#8
0
        public HttpResponseMessage Update(int id, Company company)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            UserTicket ticket = TicketManager.getTicketFromContext(this.ControllerContext);

            try
            {
                company.id = id;
                Company updatedCompany = CompanyManager.updateCompany(company, ticket.user);

                var response = Request.CreateResponse<Company>(HttpStatusCode.OK, updatedCompany);
                return response;
            }
            catch (NotAllowedException)
            {
                throw new HttpResponseException(HttpStatusCode.Forbidden);
            }
        }