Guest User

Untitled

a guest
Oct 17th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.49 KB | None | 0 0
  1. public string Picture { get; set; }
  2.  
  3. [Column(TypeName = "image")]
  4. public byte[] Image { get; set; }
  5.  
  6. [Display(Name = "Display profile Image")]
  7. public bool DisplayItem { get; set; }
  8.  
  9. <div class="editor-label">
  10. @Html.LabelFor(model => model.DisplayItem)
  11. </div>
  12. <div class="editor-field">
  13. @Html.EditorFor(model => model.DisplayItem)
  14. @Html.ValidationMessageFor(model => model.DisplayItem)
  15. </div>
  16. <div class="editor-label">
  17. @Html.LabelFor(m => m.Image)
  18. </div>
  19.  
  20. <input type="file" name="file"/>
  21.  
  22. public ActionResult Edit(string UserId)
  23. {
  24. string username = User.Identity.Name;
  25. // Fetch the userprofile
  26. UserProfile user = db.userProfiles.FirstOrDefault(u => u.UserName.Equals(username));
  27. // Construct the viewmodel
  28.  
  29. return View(user);
  30. }
  31.  
  32. [HttpPost]
  33. public ActionResult Edit(UserProfile userprofile, HttpPostedFileBase file)
  34. {
  35. if (file != null && file.ContentLength > 0)
  36. {
  37. // extract only the fielname
  38. var fileName = Path.GetFileName(file.FileName);
  39. // store the file inside ~/App_Data/uploads folder
  40. var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
  41. file.SaveAs(path);
  42. }
  43.  
  44. if (ModelState.IsValid)
  45. {
  46. string username = User.Identity.Name;
  47. // Get the userprofile
  48. UserProfile user = db.userProfiles.FirstOrDefault(u => u.UserName.Equals(username));
  49.  
  50. // Update fields
  51.  
  52. user.FirstName = userprofile.FirstName;
  53. user.LastName = userprofile.LastName;
  54. user.Email = userprofile.Email;
  55. user.Motto = userprofile.Motto;
  56.  
  57. user.PlaceOfBirth = userprofile.PlaceOfBirth;
  58. user.HowManyBikes = userprofile.HowManyBikes;
  59. user.BesideYourBeth = userprofile.BesideYourBeth;
  60. user.NicestRide = userprofile.NicestRide;
  61. user.WorstRide = userprofile.WorstRide;
  62. user.AmountKmPerYear = userprofile.AmountKmPerYear;
  63. user.AverageSpeed = userprofile.AverageSpeed;
  64. user.AbleToChatWhileRiding = userprofile.AbleToChatWhileRiding;
  65. user.PhoneNumber = userprofile.PhoneNumber;
  66.  
  67. db.Entry(user).State = EntityState.Modified;
  68.  
  69. db.SaveChanges();
  70.  
  71. return RedirectToAction("Edit", "Account");
  72. }
  73.  
  74. return View(userprofile);
  75. }
  76.  
  77. [HttpPost]
  78. public ActionResult Edit(UserProfile userprofile, HttpPostedFileBase file)
  79. {
  80.  
  81. if (file != null && file.ContentLength > 0)
  82. {
  83.  
  84.  
  85. // extract only the fielname
  86. var fileName = Path.GetFileName(file.FileName);
  87. // store the file inside ~/App_Data/uploads folder
  88. var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
  89. file.SaveAs(path);
  90. }
  91.  
  92.  
  93.  
  94. if (ModelState.IsValid)
  95. {
  96. string username = User.Identity.Name;
  97. // Get the userprofile
  98. UserProfile user = db.userProfiles.FirstOrDefault(u => u.UserName.Equals(username));
  99.  
  100. // Update fields
  101.  
  102. user.FirstName = userprofile.FirstName;
  103. user.LastName = userprofile.LastName;
  104. user.Email = userprofile.Email;
  105. user.Motto = userprofile.Motto;
  106.  
  107. user.PlaceOfBirth = userprofile.PlaceOfBirth;
  108. user.HowManyBikes = userprofile.HowManyBikes;
  109. user.BesideYourBeth = userprofile.BesideYourBeth;
  110. user.NicestRide = userprofile.NicestRide;
  111. user.WorstRide = userprofile.WorstRide;
  112. user.AmountKmPerYear = userprofile.AmountKmPerYear;
  113. user.AverageSpeed = userprofile.AverageSpeed;
  114. user.AbleToChatWhileRiding = userprofile.AbleToChatWhileRiding;
  115. user.PhoneNumber = userprofile.PhoneNumber;
  116.  
  117. db.Entry(user).State = EntityState.Modified;
  118.  
  119. db.SaveChanges();
  120.  
  121. return RedirectToAction("Edit", "Account");
  122. }
  123.  
  124. return View(userprofile);
  125. }
  126.  
  127. [HttpPost]
  128. public ActionResult Edit(UserProfile userprofile, HttpPostedFileBase file)
  129. {
  130.  
  131. if (file != null && file.ContentLength > 0)
  132. {
  133. // extract only the fielname
  134. var fileName = Path.GetFileName(file.FileName);
  135. // store the file inside ~/App_Data/uploads folder
  136.  
  137. userprofile.Image = new byte[file.ContentLength];
  138. file.InputStream.Read(userprofile.Image, 0, file.ContentLength);
  139.  
  140. var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
  141. file.SaveAs(path);
  142. }
  143. etc...
  144.  
  145. [HttpPost]
  146. public ActionResult Edit(UserProfile userprofile, HttpPostedFileBase file)
  147. {
  148.  
  149. if (file != null && file.ContentLength > 0)
  150. {
  151. // extract only the fielname
  152. var fileName = Path.GetFileName(file.FileName);
  153. // store the file inside ~/App_Data/uploads folder
  154.  
  155.  
  156.  
  157. var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
  158. file.SaveAs(path);
  159. }
  160.  
  161.  
  162.  
  163. if (ModelState.IsValid)
  164. {
  165. string username = User.Identity.Name;
  166. // Get the userprofile
  167. UserProfile user = db.userProfiles.FirstOrDefault(u => u.UserName.Equals(username));
  168.  
  169. // Update fields
  170.  
  171. user.FirstName = userprofile.FirstName;
  172. user.LastName = userprofile.LastName;
  173. user.Email = userprofile.Email;
  174. user.Motto = userprofile.Motto;
  175.  
  176. user.PlaceOfBirth = userprofile.PlaceOfBirth;
  177. user.HowManyBikes = userprofile.HowManyBikes;
  178. user.BesideYourBeth = userprofile.BesideYourBeth;
  179. user.NicestRide = userprofile.NicestRide;
  180. user.WorstRide = userprofile.WorstRide;
  181. user.AmountKmPerYear = userprofile.AmountKmPerYear;
  182. user.AverageSpeed = userprofile.AverageSpeed;
  183. user.AbleToChatWhileRiding = userprofile.AbleToChatWhileRiding;
  184. user.PhoneNumber = userprofile.PhoneNumber;
  185.  
  186. userprofile.Image = new byte[file.ContentLength];
  187. file.InputStream.Read(userprofile.Image, 0, file.ContentLength);
  188.  
  189. db.Entry(user).State = EntityState.Modified;
  190.  
  191. db.SaveChanges();
  192.  
  193. return RedirectToAction("Edit", "Account");
  194. }
  195.  
  196. return View(userprofile);
  197. }
  198.  
  199. user.Image = new byte[file.ContentLength];
  200. file.InputStream.Read(user.Image,0, file.ContentLength);
  201.  
  202. [HttpPost]
  203. public ActionResult Edit(UserProfile userprofile, HttpPostedFileBase file)
  204. {
  205.  
  206. if (file != null && file.ContentLength > 0)
  207. {
  208. // extract only the fieldname
  209. var fileName = Path.GetFileName(file.FileName);
  210. // store the file inside ~/App_Data/uploads folder
  211. var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
  212. file.SaveAs(path);
  213. }
  214.  
  215. if (ModelState.IsValid)
  216. {
  217. string username = User.Identity.Name;
  218. // Get the userprofile
  219. UserProfile user = db.userProfiles.FirstOrDefault(u => u.UserName.Equals(username));
  220.  
  221. // Update fields
  222. user.Image = new byte[file.ContentLength];
  223. file.InputStream.Read(user.Image,0, file.ContentLength);
  224.  
  225. user.FirstName = userprofile.FirstName;
  226. user.LastName = userprofile.LastName;
  227. user.Email = userprofile.Email;
  228. user.Motto = userprofile.Motto;
  229.  
  230. user.PlaceOfBirth = userprofile.PlaceOfBirth;
  231. user.HowManyBikes = userprofile.HowManyBikes;
  232. user.BesideYourBeth = userprofile.BesideYourBeth;
  233. user.NicestRide = userprofile.NicestRide;
  234. user.WorstRide = userprofile.WorstRide;
  235. user.AmountKmPerYear = userprofile.AmountKmPerYear;
  236. user.AverageSpeed = userprofile.AverageSpeed;
  237. user.AbleToChatWhileRiding = userprofile.AbleToChatWhileRiding;
  238. user.PhoneNumber = userprofile.PhoneNumber;
  239.  
  240. db.Entry(user).State = EntityState.Modified;
  241.  
  242. db.SaveChanges();
  243.  
  244. return RedirectToAction("Edit", "Account");
  245. }
  246.  
  247. return View(userprofile);
  248. }
Add Comment
Please, Sign In to add comment