Example #1
0
        public ActionResult EditStudentProfile()
        {
            bool ProfileExists = new CheckStud(User.Identity.Name).Exist;

            if (!ProfileExists)
            {
                string tempUsername = User.Identity.Name.ToString();
                var    pdata        = (from p in dbcontext.AspNetUsers
                                       where p.UserName == tempUsername
                                       select new { UserName = tempUsername }).FirstOrDefault();

                StudentProfile ptemp = new StudentProfile
                {
                    EmailID = pdata.UserName
                };
                return(View(ptemp));
            }
            else
            {
                var ProfileData = dbcontext.StudentProfiles.Where(stud => stud.EmailID == User.Identity.Name).First();
                return(View(ProfileData));
            }
        }
Example #2
0
        public ActionResult EditStudentProfile(StudentProfile model, HttpPostedFileBase FileUpload)
        {
            string filesnames = "default.jpg";

            if (FileUpload != null)
            {
                string savedFileName = DateTime.Now.ToString("MMddHHmmssfff") + Path.GetFileName(FileUpload.FileName);
                FileUpload.SaveAs(Path.Combine(Server.MapPath("~/Content/Profile"), savedFileName)); // Save the file
                filesnames = savedFileName;
            }

            bool ProfileExists = new CheckStud(User.Identity.Name).Exist;

            if (!ProfileExists)
            {
                BindCourse();
                StudentProfile insert = new StudentProfile()
                {
                    Name         = model.Name,
                    Gender       = model.Gender,
                    MobileNumber = model.MobileNumber,
                    EmailID      = model.EmailID,
                    CollegeName  = model.CollegeName,
                    //Course = model.Course,
                    //Semester = model.Semester,
                    Address     = model.Address,
                    CreatedDate = DateTime.Now,
                    Image       = filesnames,
                    // Status = true,
                    ModifiedDate = DateTime.Now
                };
                Session["UserID"] = insert.Student_ID;
                dbcontext.StudentProfiles.Add(insert);
            }
            else
            {
                BindCourse();
                var            ProfileID = new GetStudID(User.Identity.Name).ProfileID;
                StudentProfile update    = dbcontext.StudentProfiles.Find(ProfileID);
                if (update.Student_ID == ProfileID)
                {
                    update.Name = model.Name;
                    // update.Gender = model.Gender;
                    update.MobileNumber = model.MobileNumber;
                    update.EmailID      = model.EmailID;
                    update.CollegeName  = model.CollegeName;
                    //update.Course = model.Course;
                    //update.Semester = model.Semester;
                    update.Address     = model.Address;
                    update.CreatedDate = DateTime.Now;
                    if (FileUpload != null)
                    {
                        update.Image = filesnames;
                    }
                    // Status = true,
                    update.ModifiedDate = DateTime.Now;
                }
                Session["UserID"] = update.Student_ID;
                dbcontext.StudentProfiles.AddOrUpdate(update);
            }

            int alert = dbcontext.SaveChanges();

            if (alert > 0)
            {
                TempData["AlertBox"] = "<script>alert('Sucessfully Created Profile');</script>";
            }
            return(RedirectToAction("ProfileStudent", "Student"));
        }