Пример #1
0
 public static void EditProfile(EditProfileViewModel model,string userLogin)
 {
     using(DatabaseContext db = new DatabaseContext())
     {
         var user=db.Users.Where(u => u.Login == userLogin).FirstOrDefault();
         var profile=db.Profiles.Where(p=>p.Id==user.Id).FirstOrDefault();
         if(user!=null)
         {
             if (model.AvatarPath != null)
             { profile.AvatarPath = model.AvatarPath; }
             profile.Chair = model.Chair;
             profile.Country = model.Country;
             profile.Skype = model.Skype;
             profile.Phone = model.Phone;
             profile.Group = model.Group;
             db.SaveChanges();
         }
     }
 }
 public ActionResult EditProfile(EditProfileViewModel model,HttpPostedFileBase fileUpload)
 {
     if(ModelState.IsValid)
     {
         if(fileUpload!=null)
         {
             model.AvatarPath = "/Images/" + User.Identity.Name + fileUpload.FileName;
             fileUpload.SaveAs(HttpContext.Server.MapPath("~/Images/" +User.Identity.Name+fileUpload.FileName));
         }
         UserManager.EditProfile(model,User.Identity.Name);
         return RedirectToAction("Index");
     }
     else
     {
         return View(model);
     }
 }