Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ActionResult Index()
- {
- Session["userID"] = "IT14111884";
- string sessionValue = Session["userID"].ToString();
- if (Session["userID"].ToString() == null) return View("Login");
- person1 = repo.GetPeronById(sessionValue);
- var model = person1;
- //DateTime da = (DateTime)person1.DOB;
- //DateTime date2 = ;
- //DateTime.ToString("dd MMM yyyy")
- return View(model);
- }
- [HttpPost]
- public JsonResult saveChanges(person person1)
- {
- person _person = new person();
- _person.SID = person1.SID;
- _person.FirstName = person1.FirstName;
- _person.LastName = person1.LastName;
- _person.Address = person1.Address;
- _person.Phone = person1.Phone;
- _person.DOB = person1.DOB;
- _person.password = person1.password;
- _person.email = person1.email;
- //Session["_person"] = _person;
- string sessionValue = Session["userID"].ToString();
- bool status;
- if (!ModelState.IsValid) return Json(false, JsonRequestBehavior.AllowGet);
- status = repo.updatePerson(sessionValue,_person);
- return Json(status, JsonRequestBehavior.AllowGet);
- }
- [HttpPost]
- public ActionResult UploadPhoto(HttpPostedFileBase file)
- {
- if (file != null && file.ContentLength > 0)
- {
- var user = Session["userID"].ToString();
- var fileExt = Path.GetExtension(file.FileName);
- if (fileExt.ToLower().EndsWith(".png") || fileExt.ToLower().EndsWith(".jpg"))
- {
- var fileName = user + ".png";
- var filePath = HostingEnvironment.MapPath("~/Content/profile/") + fileName;
- var directory = new DirectoryInfo(HostingEnvironment.MapPath("~/Content/profile/"));
- if (directory.Exists == false)
- {
- directory.Create();
- }
- ViewBag.FilePath = filePath.ToString();
- file.SaveAs(filePath);
- return RedirectToAction("Index", new { Message = ManageMessageId.PhotoUploadSuccess });
- }
- else
- {
- return RedirectToAction("Index", new { Message = ManageMessageId.FileExtensionError });
- }
- }
- return RedirectToAction("Index", new { Message = ManageMessageId.Error });
- }
- public enum ManageMessageId
- {
- Error,
- PhotoUploadSuccess,
- FileExtensionError
- }
- public bool updatePerson(string ID,person _objPerson)
- {
- //_dbContext.people.Add(_objPerson);
- person temp = null;
- try
- {
- temp = (from p in _dbContext.people
- where p.SID == ID
- select p).SingleOrDefault();
- temp.FirstName = _objPerson.FirstName;
- temp.LastName = _objPerson.LastName;
- temp.Address = _objPerson.Address;
- temp.Phone = _objPerson.Phone;
- temp.DOB = _objPerson.DOB;
- temp.password = _objPerson.password;
- temp.email = _objPerson.email;
- //_dbContext.SaveChanges();
- //Guid id = _objPerson.Person_ID;
- if (_dbContext.SaveChanges() > 0)
- {
- return true;
- }
- }
- catch (DbUpdateException e)
- {
- string msg = (e.InnerException.Message);
- //Console.ReadLine();
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement