示例#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));
        }
        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);
        }