public ActionResult EditDetail(PetOwnerProfile info, HttpPostedFileBase file, Image ImageModel) { int imageid; PODBProjectEntities entities = new PODBProjectEntities(); String userId = User.Identity.GetUserId(); PostPhoto photo = new PostPhoto(); String path = photo.PostPhotoPetOwner(file); if (file != null) { imageid = entities.Images.Where(e => e.imagePath.Equals(path)).FirstOrDefault().imageID; } else { imageid = entities.PetOwnerProfiles.Where(e => e.Id.Equals(userId)).FirstOrDefault().imageID; } using (PODBProjectEntities image = new PODBProjectEntities()) { ImageModel.imageID = imageid; ImageModel.imagePath = path; ImageModel.imageType = "PetOwnerProfile"; entities.Entry(ImageModel).State = EntityState.Modified; entities.SaveChanges(); } using (entities) { var result = entities.PetOwnerProfiles.SingleOrDefault(e => e.Id == userId); if (result != null) { if (info.subdivision == null) { info.subdivision = "none"; } else { } var user = new PetOwnerProfile() { Id = userId, fullName = info.fullName, gender = info.gender, street = info.street, subdivision = info.subdivision, barangay = info.barangay, contactNumber = info.contactNumber, email = entities.AspNetUsers.Where(e => e.Id.Equals(userId)).FirstOrDefault().Email, registerDate = entities.PetOwnerProfiles.Where(e => e.Id.Equals(userId)).FirstOrDefault().registerDate, updateDate = DateTime.Now, imageID = imageid }; entities.SaveChanges(); } return(RedirectToAction("ViewDetail", "Manage")); } }
public ActionResult PetOwnerProfile(PetOwnerProfile info, HttpPostedFileBase file, Image ImageModel) { PODBProjectEntities entities = new PODBProjectEntities(); String userId = User.Identity.GetUserId(); PostPhoto photo = new PostPhoto(); String path = photo.PostPhotoPetOwner(file); int imageid = entities.Images.Where(e => e.imagePath.Equals(path)).FirstOrDefault().imageID; string Email = entities.AspNetUsers.Where(e => e.Id.Equals(userId)).FirstOrDefault().Email; if (info.subdivision == null) { info.subdivision = "N/A"; } else { } var user = new PetOwnerProfile() { Id = userId, fullName = info.fullName, gender = info.gender, street = info.street, subdivision = info.subdivision, barangay = info.barangay, contactNumber = info.contactNumber, email = Email, registerDate = DateTime.Now, updateDate = DateTime.Now, imageID = imageid }; entities.PetOwnerProfiles.Add(user); entities.SaveChanges(); if (!entities.AspNetUsers.Where(e => e.Email.Equals(Email)).FirstOrDefault().EmailConfirmed) { Session.Abandon(); AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); ModelState.AddModelError("", "You need to confirm your email address"); return(RedirectToAction("ConfirmBeforeLogin", "Account")); } else { return(RedirectToAction("Index", "Home")); } }