public HttpResponseMessage Add(ViewCompany comp)
 {
     var companyGenerator = new CompanyGenerator();
     
     var response = Request.CreateResponse(HttpStatusCode.OK, companyGenerator.ParseCompany(repository.Add(companyGenerator.GenerateCompany(comp,15,10))));
     return response;
 }
        /// <summary>
        /// This will generate a new company from a view company
        /// </summary>
        /// <param name="comp">the company to be generated</param>
        /// <returns>the company that should be added to the database</returns>
        public Company GenerateCompany(ViewCompany comp, int _lenghtOfPassword, int _numberOfAlphabeticCharacters)
        {

            var result = new Company() {Active = true, Name = comp.Name, PhoneNr = comp.PhoneNr};

            //Generates a random password, and makes a new user with the correct email
            var password = System.Web.Security.Membership.GeneratePassword(_lenghtOfPassword, _numberOfAlphabeticCharacters);
            var um = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new DAL.Context.Context()));
            var user = new ApplicationUser()
            {
                UserName = comp.Email,
                Email = comp.Email
            };

            um.Create(user, password);
            //Generates the access string by encoding the email and the password into an array of bytes.
            var bytes = System.Text.Encoding.UTF8.GetBytes(comp.Email + ":" + password);
            result.AccessString = System.Convert.ToBase64String(bytes);
            result.Active = true;

            //This will be so that the database will make the relation between the two.
            var item = um.FindByEmail(comp.Email);
            result.IdentityId = item.Id;

            return result;
        }
        public HttpResponseMessage Update(ViewCompany comp)
        {
            var companyGenerator = new CompanyGenerator();

            var company = companyGenerator.ParseViewCompany(comp);
            HttpResponseMessage response;
            if (repository.Update(company))
            {
                response = Request.CreateResponse(HttpStatusCode.OK, true);
            }
            else
            {
                response = Request.CreateResponse(HttpStatusCode.Conflict);
            }
            
            return response;
        }
 /// <summary>
 /// This will parse a viewcompany to a company
 /// </summary>
 /// <param name="company">the viewcompany to be converted</param>
 /// <returns>a company corresponding to the given viewcompany</returns>
 public Company ParseViewCompany(ViewCompany company)
 {
     var um = new UserManager<IdentityUser>(new UserStore<IdentityUser>(new DAL.Context.Context()));
     return new Company() { Active = company.Active, Name = company.Name, PhoneNr = company.PhoneNr, AccessString = company.AccessString, Employees = company.Employees, Identity = um.FindByEmail(company.Email) };
 }