public ActionResult CreateCompany(CompanyAddBindingModel NewCompany) { var postTask = ApiHelper.ApiClient.PostAsJsonAsync <CompanyAddBindingModel>("api/Company", NewCompany); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("Companies")); } else { ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator."); return(View("NewCompany")); } }
public IHttpActionResult CreateCompany([FromBody] CompanyAddBindingModel Model) { if (ModelState.IsValid == false) { return(BadRequest("invalid data.")); } if (Model == null) { return(BadRequest("any information about company was specified")); } else { Company NewCompany = new Company(); NewCompany.Name = Model.Name; NewCompany.Address = Model.Address; NewCompany.City = Model.City; NewCompany.Nip = Model.Nip; if (Model.IndustryId == null) { NewCompany.IndustryType = null; } else { Industry CurrentIndustry = CompanyContext.Industries.SingleOrDefault(i => i.Id == Model.IndustryId); NewCompany.IndustryType = CurrentIndustry; } string UserId = User.Identity.GetUserId(); ApplicationUser AppUser = CompanyContext.Users.Single(u => u.Id == UserId); NewCompany.userID = AppUser; CompanyContext.Companies.Add(NewCompany); CompanyContext.SaveChanges(); return(Ok()); } }