예제 #1
0
        public async Task<IHttpActionResult> PutCompany( CompanyEditDTO company_edit)
        {
            string reg = User.Identity.GetUserId();
            Company owner = await db.Companies.Where(d => d.registrationId == reg).SingleOrDefaultAsync();

            if (owner == null)
            {
                return StatusCode(HttpStatusCode.Forbidden);
            }
            int owner_id = owner.Id;
            
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            Company company = new Company()
            {
                companyName = company_edit.name,
                category = company_edit.company_category,
                wallpaper = company_edit.wall_pic,
                profilePicture =company_edit.profile_pic,
                website = company_edit.web_url,
                address = company_edit.physical_address,
                fax = company_edit.fax_num,
                fb_url = company_edit.facebook,
                tel = company_edit.telephone,
                twt_url = company_edit.twitter,
                ggle_plus = company_edit.google_plus,
                statusMessage = company_edit.statusMessage,
                Id = owner_id,
                lkdn_url = company_edit.linkdn
            };

            foreach (PropertyInfo propertyInfo in owner.GetType().GetProperties())
            {
                if (propertyInfo.GetValue(company, null) == null)
                    propertyInfo.SetValue(company, propertyInfo.GetValue(owner, null), null);
            }

            try
            {
                db.Entry(owner).CurrentValues.SetValues(company);
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CompanyExists(owner_id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.OK);
        }
예제 #2
0
        public async Task<IHttpActionResult> CompanyRegistration(CompanyRegDTO data)
        {
             
            RegisterBindingModel model =new RegisterBindingModel
            {
                Email = data.email_address,
                Password = data.password,
                ConfirmPassword= data.confirm_password
                
            };
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var user = new ApplicationUser() { UserName = model.Email, Email = model.Email };

            IdentityResult result = await UserManager.CreateAsync(user, model.Password);

            if (!result.Succeeded)
            {
                return GetErrorResult(result);
            }
            else
            {
                ApplicationUser client = await UserManager.FindByEmailAsync(model.Email);
                Company company = new Company()
                {
                    companyName = data.company_name,
                    category = data.company_category,
                    email = data.email_address,
                    registrationId = client.Id
                };

                db.Companies.Add(company);
                await db.SaveChangesAsync();
            }
            return Ok();
        }