Пример #1
0
        public ActionResult ManageAccount(String Message)
        {
            ViewBag.StatusMessage = Message;
            AccountRepository userRep = new AccountRepository();
            User user = userRep.GetCurrentUser();
            UserImage img = userRep.GetCurrentUserImage();
            string path = "/Uploads/UserImage/m1.jpeg";
            if (img != null)
            {
                path = img.imagePath;
            }

            ManageAccountViewModel ma = new ManageAccountViewModel
            {
                FirstName = user.fname,
                LastName = user.lname,

                Address1 = user.addr1,
                Address2 = user.addr2,
                City = user.city,
                State = user.state,
                Zip = user.zip,

                PhoneNumber = user.phNo,
                Email = user.UserID,

                ImageFilename = path,
                //ImageFilename = Path.Combine(Server.MapPath("~/Images/userImages/"), "cpc111020.jpg")
                IsMentor = userRep.IsCurrentUserMentor()
            };
            ViewBag.userfname = System.Web.HttpContext.Current.Session["fname"] as String;
            return View(ma);
        }
Пример #2
0
        public FileResult DisplayResumePdf()
        {
            AccountRepository userRep = new AccountRepository();
            User user = userRep.GetCurrentUser();

            // Maybe put as a function in repository, but whatever
            MentorResume resume = context.MentorResumes.Where(u => u.fk_mentorId == user.ID).FirstOrDefault();

            if (resume == null)
            {
                return null;
            }

            return File(resume.filePath, "application/pdf");
        }
Пример #3
0
        public ActionResult ManageAccount(ManageAccountViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }
            ViewBag.userfname = System.Web.HttpContext.Current.Session["fname"] as String;
            AccountRepository userRep = new AccountRepository();
            userRep.ChangeCurrentUserName(model.FirstName, model.LastName);
            userRep.ChangeCurrentUserAddress(model.Address1, model.Address2, model.City, model.State, model.Zip);
            userRep.ChangeCurrentUserEmail(model.Email);
            userRep.ChangeCurrentUserPhone(model.PhoneNumber);
            userRep.ChangeCurrentUserPassword(model.OldPassword, model.NewPassword);

            User user = userRep.GetCurrentUser();

            if (model.ImageFile != null && model.ImageFile.ContentLength > 0)
            {
                string directory = "/Uploads/UserImage/";
                string[] tmp = model.Email.Split('@');

                var extension = Path.GetExtension(model.ImageFile.FileName);
                var fileName = tmp[0] + "-" + user.user_type + extension;
                var path = Path.Combine(Server.MapPath(directory), fileName);
                model.ImageFile.SaveAs(path);

                userRep.ChangeUserImage(directory+fileName, extension);
                model.ImageFilename = directory + fileName;
            }
            else
            {
                UserImage img = userRep.GetCurrentUserImage();
                string path = "/Uploads/UserImage/m1.jpeg";
                if (img != null)
                {
                    path = img.imagePath;
                }

                model.ImageFilename = path;
            }

            if (model.PdfFile != null && model.PdfFile.ContentLength > 0)
            {
                string directory = "/Uploads/Resume/";
                string[] tmp = model.Email.Split('@');

                var extension = Path.GetExtension(model.PdfFile.FileName);
                var fileName = tmp[0] + extension;
                var path = Path.Combine(Server.MapPath(directory), fileName);
                model.PdfFile.SaveAs(path);     // save physical copy in server

                // save path in database
                MentorResume pdf = context.MentorResumes.Where(u => u.fk_mentorId == user.ID).FirstOrDefault();

                if (pdf != null)    // edit
                {
                    pdf.filePath = directory+fileName;
                }
                else     // create new
                {
                    pdf = new MentorResume();
                    pdf.fk_mentorId = user.ID;
                    pdf.filePath = directory + fileName;

                    context.MentorResumes.Add(pdf);
                }

                /*
                try
                {
                    context.SaveChanges();
                }
                catch (Exception e)
                {

                }      */
                context.SaveChanges();
            }

            model.IsMentor = userRep.IsCurrentUserMentor();

            return model.IsMentor ? RedirectToAction("Index", "Mentor") : RedirectToAction("Index", "Student");
        }