Advertisement
Guest User

Untitled

a guest
Dec 13th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. public ActionResult Index()
  2. {
  3. Session["userID"] = "IT14111884";
  4. string sessionValue = Session["userID"].ToString();
  5. if (Session["userID"].ToString() == null) return View("Login");
  6.  
  7. person1 = repo.GetPeronById(sessionValue);
  8. var model = person1;
  9. //DateTime da = (DateTime)person1.DOB;
  10. //DateTime date2 = ;
  11. //DateTime.ToString("dd MMM yyyy")
  12. return View(model);
  13. }
  14.  
  15.  
  16. [HttpPost]
  17. public JsonResult saveChanges(person person1)
  18. {
  19. person _person = new person();
  20. _person.SID = person1.SID;
  21. _person.FirstName = person1.FirstName;
  22. _person.LastName = person1.LastName;
  23. _person.Address = person1.Address;
  24. _person.Phone = person1.Phone;
  25. _person.DOB = person1.DOB;
  26. _person.password = person1.password;
  27. _person.email = person1.email;
  28. //Session["_person"] = _person;
  29.  
  30. string sessionValue = Session["userID"].ToString();
  31. bool status;
  32. if (!ModelState.IsValid) return Json(false, JsonRequestBehavior.AllowGet);
  33. status = repo.updatePerson(sessionValue,_person);
  34.  
  35. return Json(status, JsonRequestBehavior.AllowGet);
  36.  
  37. }
  38.  
  39.  
  40. [HttpPost]
  41. public ActionResult UploadPhoto(HttpPostedFileBase file)
  42. {
  43. if (file != null && file.ContentLength > 0)
  44. {
  45. var user = Session["userID"].ToString();
  46. var fileExt = Path.GetExtension(file.FileName);
  47.  
  48.  
  49. if (fileExt.ToLower().EndsWith(".png") || fileExt.ToLower().EndsWith(".jpg"))
  50. {
  51. var fileName = user + ".png";
  52. var filePath = HostingEnvironment.MapPath("~/Content/profile/") + fileName;
  53. var directory = new DirectoryInfo(HostingEnvironment.MapPath("~/Content/profile/"));
  54.  
  55. if (directory.Exists == false)
  56. {
  57. directory.Create();
  58. }
  59. ViewBag.FilePath = filePath.ToString();
  60. file.SaveAs(filePath);
  61. return RedirectToAction("Index", new { Message = ManageMessageId.PhotoUploadSuccess });
  62.  
  63. }
  64. else
  65. {
  66. return RedirectToAction("Index", new { Message = ManageMessageId.FileExtensionError });
  67.  
  68. }
  69.  
  70. }
  71. return RedirectToAction("Index", new { Message = ManageMessageId.Error });
  72.  
  73. }
  74.  
  75.  
  76. public enum ManageMessageId
  77. {
  78. Error,
  79. PhotoUploadSuccess,
  80. FileExtensionError
  81.  
  82. }
  83.  
  84. public bool updatePerson(string ID,person _objPerson)
  85. {
  86. //_dbContext.people.Add(_objPerson);
  87. person temp = null;
  88. try
  89. {
  90. temp = (from p in _dbContext.people
  91. where p.SID == ID
  92. select p).SingleOrDefault();
  93. temp.FirstName = _objPerson.FirstName;
  94. temp.LastName = _objPerson.LastName;
  95. temp.Address = _objPerson.Address;
  96. temp.Phone = _objPerson.Phone;
  97. temp.DOB = _objPerson.DOB;
  98. temp.password = _objPerson.password;
  99. temp.email = _objPerson.email;
  100. //_dbContext.SaveChanges();
  101. //Guid id = _objPerson.Person_ID;
  102. if (_dbContext.SaveChanges() > 0)
  103. {
  104. return true;
  105. }
  106.  
  107.  
  108.  
  109. }
  110. catch (DbUpdateException e)
  111. {
  112. string msg = (e.InnerException.Message);
  113. //Console.ReadLine();
  114.  
  115. }
  116. return false;
  117.  
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement