public ActionResult Edit(Member member, HttpPostedFileBase photo)
        {
            if (ModelState.IsValid)
            {
                UploadPhoto(member, photo);
                profile.Members.First(m => m.ID == member.ID).update(member);
                return RedirectToAction("Index");
            }

            return View(member);
        }
Exemplo n.º 2
0
 public void update(Member member)
 {
     Name = member.Name;
     Bio = member.Bio;
     Instruments = member.Instruments;
     Gear = member.Gear;
     if (!string.IsNullOrEmpty(member.PhotoUrl))
     {
         PhotoUrl = member.PhotoUrl;
     }
 }
 public ActionResult Create(Member member, HttpPostedFileBase photo)
 {
     try
     {
         UploadPhoto(member, photo);
         member.ID = Guid.NewGuid();
         member.Position = profile.Members.Count;
         profile.Members.Add(member);
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
 private void UploadPhoto(Member member, HttpPostedFileBase photo)
 {
     if (photo != null && photo.ContentLength > 0)
     {
         try
         {
             member.PhotoUrl = Path.GetFileName(photo.FileName);
             var path = Path.Combine(Server.MapPath("~/Content/images/photos"), member.PhotoUrl);
             photo.SaveAs(path);
         }
         catch (Exception ex)
         {
             member.PhotoUrl = string.Empty;
             ModelState.AddModelError("photo", string.Format("Error Uploading Image: {0}", ex.Message));
         }
     }
 }