public async Task <ActionResult> Create([Bind(Include = "ID,ApplicationLink,Company,DatePosted,Experience,Hours,JobID,JobTitle,LanguagesUsed,Location,Salary")] Job job) { if (ModelState.IsValid) { context.Jobs.Add(job); await context.SaveChangesAsync(); return(RedirectToAction("Index")); } PopulateCompanyDropdownList(); return(View(job)); }
public async Task <ActionResult> Create([Bind(Include = "CompanyName,CompanyLink,Address,City,State,ZipCode,Latitude,Longitude,CareerPage,CompanyType,IndustryServed,LanguagesUsed,Files")] Company company, HttpPostedFileBase upload) { var _company = db.Companies.Find(company.CompanyName); if (_company != null) { ViewBag.ErrorMessage = company.CompanyName + " already exists."; } else if (ModelState.IsValid) { if (upload != null && upload.ContentLength > 0) { var logo = new CompanyFile { FileName = System.IO.Path.GetFileName(upload.FileName), FileType = FileType.Logo, ContentType = upload.ContentType, CompanyName = company.CompanyName }; using (var reader = new System.IO.BinaryReader(upload.InputStream)) { logo.Content = reader.ReadBytes(upload.ContentLength); } company.Files = new List <CompanyFile> { logo }; } db.Companies.Add(company); await db.SaveChangesAsync(); return(RedirectToAction("Details", new { id = company.CompanyName })); } return(View(company)); }
public async Task <ActionResult> UserProfile([Bind(Include = "FirstName, LastName, Location, Languages, Experience")] User _userProfile) { if (ModelState.IsValid) { var userName = User.Identity.GetUserName();//get user's username for database reference //get row in database that corresponds to the user so we can edit data in specific columns var user = (from u in db.Users where u.UserName == userName select u).First(); //check incoming data to make sure there is something there and that it doesnt match what is already in the database before updating if ((_userProfile.FirstName != user.FirstName) && (_userProfile.FirstName.Trim().Length != 0)) { user.FirstName = _userProfile.FirstName; } if ((_userProfile.LastName != user.LastName) && (_userProfile.LastName.Trim().Length != 0)) { user.LastName = _userProfile.LastName; } if ((_userProfile.Location != user.Location) && (_userProfile.Location.Trim().Length != 0)) { user.Location = _userProfile.Location; } if ((_userProfile.Languages != user.Languages) && (_userProfile.Languages.Trim().Length != 0)) { user.Languages = _userProfile.Languages; } if ((_userProfile.Experience != user.Experience) && (_userProfile.Experience.Trim().Length != 0)) { user.Experience = _userProfile.Experience; } await db.SaveChangesAsync(); } return(View(_userProfile)); }