public FileContentResult VerDocs(string tipoDoc, int profId, int titId)
        {
            var    profesional  = ProfVM.GetListaProfDummy().Where(r => r.profId == profId).FirstOrDefault();
            string _IdMatricula = profesional.profId.ToString() + "_" + profesional.ListaTitulos.Where(r => r.titId == titId).FirstOrDefault().titMatricula.ToString();

            switch (tipoDoc)
            {
            case "docTitulo":
            {
                var fullPathToFile = Server.MapPath("~/UploadedFiles/Profesionales/" + _IdMatricula + "/" + _IdMatricula + "_Titulo.pdf");
                var mimeType       = "application/pdf";
                var fileContents   = System.IO.File.ReadAllBytes(fullPathToFile);

                return(new FileContentResult(fileContents, mimeType));
            }
            break;

            case "docAnalitico":
            {
                var fullPathToFile = Server.MapPath("~/UploadedFiles/Profesionales/" + _IdMatricula + "/" + _IdMatricula + "_Analitico.pdf");
                var mimeType       = "application/pdf";
                var fileContents   = System.IO.File.ReadAllBytes(fullPathToFile);

                return(new FileContentResult(fileContents, mimeType));
            }
            break;

            default:
                return(null);

                break;
            }
        }
Beispiel #2
0
        public ProfPage(int _profId, int _role)
        {
            InitializeComponent();

            role   = _role;
            profId = _profId;

            BindingContext = model = new ProfVM(_role, _profId);
            model._profId  = profId;
            model._role    = _role;
        }
        public ActionResult Anceta(ProfVM model)
        {
            //if (!ModelState.IsValid)
            // {
            //     return HttpNotFound();
            //}
            using (BlogContext db = new BlogContext())
            {
                string surname;

                ProfDTO dto = new ProfDTO();

                dto.Name = model.Name.ToUpper();

                if (string.IsNullOrWhiteSpace(model.Surname))
                {
                    surname = model.Surname.Replace(" ", "-").ToLower();
                }
                else
                {
                    surname = model.Surname.Replace(" ", "-").ToLower();
                }
                if (db.Profs.Any(x => x.Email == model.Email))
                {
                    ModelState.AddModelError("", "That email already exist.");
                    return(View(model));
                }
                if (dto.Age < 0 || dto.Age > 145)
                {
                    ModelState.AddModelError("", "That age don`t seemed to be real.");
                    return(View(model));
                }

                dto.Surname = surname;

                dto.Password = model.Password;
                dto.Email    = model.Email;
                dto.Age      = model.Age;
                dto.Gender   = model.Gender;

                db.Profs.Add(dto);
                db.SaveChanges();
            }
            return(RedirectToAction("ShowAnceta"));
        }
        public ActionResult Profile(ProfVM model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            using (Db db = new Db())
            {
                ProfDTO dto = new ProfDTO();


                if (string.IsNullOrWhiteSpace(model.Name))
                {
                    dto.Name = model.Name.Replace(" ", "-").ToLower();
                }

                if (string.IsNullOrWhiteSpace(model.Surname))
                {
                    dto.Surname = model.Surname.Replace(" ", "-").ToLower();
                }

                if (db.Profs.Any(x => x.Email == model.Email))
                {
                    ModelState.AddModelError("", "That email already exist.");
                    return(View(model));
                }
                if (dto.Age < 0 || dto.Age > 145)
                {
                    ModelState.AddModelError("", "That age unreal.");
                    return(View(model));
                }
                dto.Name    = model.Name;
                dto.Surname = model.Surname;

                dto.Password = model.Password;
                dto.Email    = model.Email;
                dto.Age      = model.Age;
                //  dto.Gender = model.Gender;

                db.Profs.Add(dto);
                db.SaveChanges();
            }
            return(RedirectToAction("ShowProfile"));
        }
        public ActionResult EditUser(ProfVM model)
        {
            //Проверяем модель на валидность
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            using (Db db = new Db())
            {
                //Получаем id страницы
                int id = model.Id;


                //Получаем страницу по Id
                ProfDTO dto = db.Profs.Find(id);
                //Присваиваем name из полученной модели в DTO
                dto.Name = model.Name;

                //Проверяем email на уникальность
                if (db.Profs.Where(x => x.Id != id).Any(x => x.Email == model.Email))
                {
                    ModelState.AddModelError("", "That email already exist.");
                    return(View(model));
                }


                //Присвоить остальные значения в класс DTO
                dto.Surname = model.Surname;

                dto.Password = model.Password;
                dto.Email    = model.Email;
                dto.Age      = model.Age;

                //Сохраняем изменения в базу
                db.SaveChanges();
            }

            //Установить сообщение в TempData
            TempData["SM"] = "You have edited the user.";

            //Переадресация пользователя
            return(RedirectToAction("ShowProfile"));
        }
        public ActionResult EditUser(int id)
        {
            //Обьявляем модель PageVM
            ProfVM model;

            using (Db db = new Db())
            {
                //Получаем Id пользователя
                ProfDTO dto = db.Profs.Find(id);

                //Проверяем доступен ли он (Валидация)
                if (dto == null)
                {
                    return(Content("The page does not exist."));
                }

                // Инициализируем модель данными DTO через конструктор в классе pкщаVM
                model = new ProfVM(dto);
            }
            //Возвращаем модель в представление
            return(View(model));
        }
        public ActionResult SubirDocs(HttpPostedFileBase docTitulo, HttpPostedFileBase docAnalitico, int profId, int titId)
        {
            try
            {
                //if (Request.Files.Count > 0)
                //{
                //    HttpFileCollectionBase files = Request.Files;

                //    docTitulo = files[0];
                //    docAnalitico = files[1];

                //}

                //if (docTitulo.ContentLength > 0)
                //{
                //    string _FileName = Path.GetFileName(docTitulo.FileName);
                //    string _path = Path.Combine(Server.MapPath("~/UploadedFiles"), _FileName);
                //    docTitulo.SaveAs(_path);
                //}
                //ViewBag.Message1 = "Titulo subido satisfactoriamente!!";


                //if (docAnalitico.ContentLength > 0)
                //{
                //    string _FileName = Path.GetFileName(docAnalitico.FileName);
                //    string _path = Path.Combine(Server.MapPath("~/UploadedFiles"), _FileName);
                //    docAnalitico.SaveAs(_path);
                //}
                //ViewBag.Message2 = "Titulo subido satisfactoriamente!!";
                //return PartialView();

                var profesional = ProfVM.GetListaProfDummy().Where(r => r.profId == profId).FirstOrDefault();


                if (Request.Files.Count > 0)
                {
                    HttpFileCollectionBase files = Request.Files;
                    string _IdMatricula          = profesional.profId.ToString() + "_" + profesional.ListaTitulos.Where(r => r.titId == titId).FirstOrDefault().titMatricula.ToString();

                    //Titulo
                    if (files["docTitulo"] != null)
                    {
                        docTitulo = files["docTitulo"];

                        if (docTitulo.ContentLength > 0)
                        {
                            string _FileName = _IdMatricula + "_Titulo" + Path.GetExtension(docTitulo.FileName);
                            System.IO.Directory.CreateDirectory(Server.MapPath("~/UploadedFiles/Profesionales/" + _IdMatricula));
                            string _path = Path.Combine(Server.MapPath("~/UploadedFiles/Profesionales/" + _IdMatricula), _FileName);
                            docTitulo.SaveAs(_path);
                        }
                        ViewBag.Message1 = "Titulo subido satisfactoriamente!!";
                    }

                    //Analitico
                    if (files["docAnalitico"] != null)
                    {
                        docAnalitico = files["docAnalitico"];

                        if (docAnalitico.ContentLength > 0)
                        {
                            string _FileName = _IdMatricula + "_Analitico" + Path.GetExtension(docAnalitico.FileName);
                            System.IO.Directory.CreateDirectory(Server.MapPath("~/UploadedFiles/Profesionales/" + _IdMatricula));
                            string _path = Path.Combine(Server.MapPath("~/UploadedFiles/Profesionales/" + _IdMatricula), _FileName);
                            docAnalitico.SaveAs(_path);
                        }
                        ViewBag.Message2 = "Analitico subido satisfactoriamente!!";
                    }

                    return(PartialView());
                }

                ViewBag.Message = "No se subio ningun archivo.";
                return(PartialView());
            }
            catch (Exception ex)
            {
                ViewBag.Message = "Ocurrio un error! Intente nuevamente.";
                return(PartialView());
            }
        }
        public ActionResult SubirDocs(int profId, int titId)
        {
            var titulo = ProfVM.GetListaProfDummy().Where(r => r.profId == profId).FirstOrDefault().ListaTitulos.Where(r => r.titId == titId).FirstOrDefault();

            return(PartialView(titulo));
        }
        // GET: DigitDocs
        public ActionResult Index()
        {
            var model = ProfVM.GetProfDummy();

            return(View(model));
        }