// GET: TeamProfiles/Create // Team profile create page for administrators public ActionResult Create() { ProfileIndexViewModel editView = new ProfileIndexViewModel(); editView.teamProfile = new profile(); editView.teamProfile.pic = "~/Images/no_image.jpg"; return View(editView); }
public ActionResult List() { List<profile> profileList = (from pro in db.profile where pro.status == 1 select pro).ToList(); List<ProfileIndexViewModel> viewList = new List<ProfileIndexViewModel>(); foreach (var pro in profileList) { ProfileIndexViewModel tp = new ProfileIndexViewModel(); tp.teamProfile = pro; viewList.Add(tp); } return View(viewList.ToList()); }
public async Task<ActionResult> Create(ProfileIndexViewModel editView) { if (ModelState.IsValid) { profile pro = editView.teamProfile; var validImageTypes = new string[] { "image/gif", "image/jpeg", "image/jpg", "image/png" }; if (editView.picFile != null && editView.picFile.ContentLength > 0) { if (!validImageTypes.Contains(editView.picFile.ContentType)) { ModelState.AddModelError("ImageUpload", "Please choose either a GIF, JPG or PNG image."); } var uploadDir = "~/images/teamprofile"; var newFileName = String.Format("{0}_{1}_{2}", "Profile", DateTime.Now.ToString("yyyyMMddHHmmssfff"), Path.GetFileName(editView.picFile.FileName)); var imagePath = Path.Combine(Server.MapPath(uploadDir), newFileName); editView.picFile.SaveAs(imagePath); var imageUrl = Path.Combine(uploadDir, Path.GetFileName(imagePath)); pro.pic = "~/images/teamprofile/" + newFileName; } pro.status = 1; db.profile.Add(pro); await db.SaveChangesAsync(); return RedirectToAction("Index"); } return View(editView); }
public async Task<ActionResult> Delete(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } profile pro = await db.profile.FindAsync(id); if (pro == null) { return HttpNotFound(); } else if (pro.status == 0) { return HttpNotFound(); } ProfileIndexViewModel editView = new ProfileIndexViewModel(); editView.teamProfile = pro; return View(editView); }