public ActionResult Edit(EditMyProfileViewModel profile)
        {
            if (ModelState.IsValid)
            {
				var m = db.Profiles.Find(profile.Id);
				m.Firstname = profile.Firstname;
				m.Lastname = profile.Lastname;
				m.Phone = profile.Phone;
				m.Email = profile.Email;
				m.Education = profile.Education;
				m.Skype = profile.Skype;

				if (profile.Picture != null && profile.Picture.ContentLength > 0)
				{
					var extension = Path.GetExtension(profile.Picture.FileName).ToLowerInvariant().Substring(1);
					if (!ConfigurationManager.AppSettings["AllowedImageExtensions"].Contains(extension))
					{
						ModelState.AddModelError("Picture", "The file type is not allowed. (jpg, jpeg, gif and png.)");
						return View(profile);
					}
				}

				if (profile.Picture != null && profile.Picture.ContentLength > 0)
				{
					var extension = Path.GetExtension(profile.Picture.FileName).ToLowerInvariant();

					var old = Path.Combine(Server.MapPath(String.Concat("~", m.PicturePath)));
					if (System.IO.File.Exists(old))
					{
						System.IO.File.Delete(old);
					}

					var filename = String.Concat(m.Id, "-ProfilePicture", extension);
					var path = Path.Combine(Server.MapPath("~/Uploads/Profile"), filename);
					profile.Picture.SaveAs(path);

					m.PicturePath = String.Concat("/Uploads/Profile/", filename);
				}


                db.Entry(m).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(profile);
        }
        public ActionResult Edit(int? id)
        {
			bool EditGranted = false;
			string Username = User.Identity.Name;

			var query = from a in db.Profiles where a.Username == Username select a;

			foreach (Profile a in query)
			{
				if (a.Id == id)
				{
					EditGranted = true;
				}
			}

			if (EditGranted == true)
			{
				Profile profile = db.Profiles.Find(id);

				var model = new EditMyProfileViewModel
				{
					Id = profile.Id,
					Firstname = profile.Firstname,
					Lastname = profile.Lastname,
					Education = profile.Education,
					Email = profile.Email,
					Phone = profile.Phone,
					Skype = profile.Skype,
					PicturePath = profile.PicturePath
				};

				return View(model);
			}
			else
			{
				return RedirectToAction("Index");
			}
        }