示例#1
0
        public IHttpActionResult Post([FromBody] ManagementCompany managementCompany)
        {
            try
            {
                if (managementCompany == null)
                {
                    return(BadRequest("ManagementCompany cannot be null"));
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var managementCompanyRepository = new Models.ManagementCompanyRepository();
                var newManagementCompany        = managementCompanyRepository.Save(managementCompany);
                if (newManagementCompany == null)
                {
                    return(Conflict());
                }
                return(Created <ManagementCompany>(Request.RequestUri + newManagementCompany.ManagementCompanyId.ToString(),
                                                   newManagementCompany));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
示例#2
0
        // PUT: api/ManagementCompanies/5
        //[Authorize(Roles = "admin, company")]
        public IHttpActionResult Put(int id, [FromBody] ManagementCompany managementCompany)
        {
            try
            {
                if (managementCompany == null)
                {
                    return(BadRequest("ManagementCompany cannot be null"));
                }
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var managementCompanyRepository = new Models.ManagementCompanyRepository();
                var updatedManagementCompany    = managementCompanyRepository.Save(id, managementCompany);
                if (updatedManagementCompany == null)
                {
                    return(NotFound());
                }
                return(Ok());
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }