public ActionResult AddLab(LabTable lab) { if (Session["User"] != null) { var user = (UserTable)Session["User"]; lab.UserID = user.UserID; if (ModelState.IsValid) { var findlab = db.LabTables.Where(d => d.EmailAddress == lab.EmailAddress).FirstOrDefault(); if (findlab == null) { db.LabTables.Add(lab); db.SaveChanges(); if (lab.LogoFile != null) { var folder = "~/Content/LabPhotos"; var file = string.Format("{0}.png", lab.LabID); var response = FileHelpers.UploadPhoto(lab.LogoFile, folder, file); if (response) { var pic = string.Format("{0}/{1}", folder, file); lab.Photo = pic; db.Entry(lab).State = EntityState.Modified; db.SaveChanges(); return(View("UnderReview")); } } } else { ViewBag.Message = "Email Already Registered"; } } } else { return(RedirectToAction("Login")); } ViewBag.AccountTypeID = new SelectList(db.AccountTypeTables.ToList(), "AccountTypeID", "Name", lab.AccountTypeID); return(View(lab)); }
// PUT: odata/LabTables(5) public IHttpActionResult Put([FromODataUri] int key, Delta <LabTable> patch) { Validate(patch.GetEntity()); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } LabTable labTable = db.LabTables.Find(key); if (labTable == null) { return(NotFound()); } patch.Put(labTable); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!LabTableExists(key)) { return(NotFound()); } else { throw; } } return(Updated(labTable)); }