public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return this.RedirectToAction("Index", "ManageDiplomas");
            }

            int intId = id ?? 0;
            var diploma = this.diplomas.GetObjectById(intId);
            if (diploma == null)
            {
                this.TempData["Message"] = "Дипломата не бе намерена!";
                return this.RedirectToAction("Index", "ManageDiplomas");
            }

            var result = new StudentDiplomaViewModel();

            var studentDetails = this.students.GetAll()
                                              .Where(s => s.SelectedDiploma.Id == diploma.Id)
                                              .Include(s => s.User)
                                              .To<SimpleStudentViewModel>()
                                              .FirstOrDefault();
            result.Student = studentDetails;

            var diplomaModel = this.diplomas.GetAll()
                                             .Where(d => d.Id == intId)
                                             .Include(d => d.Teacher)
                                             .Include(d => d.Tags)
                                             .To<DisplayDiplomaViewModel>();

            result.Diploma = diplomaModel.FirstOrDefault();
            result.Diploma.ContentCSV = diploma.ContentCSV.Split(new char[] { GlobalConstants.ContentSeparator }, System.StringSplitOptions.RemoveEmptyEntries).ToList();
            result.Diploma.TeacherID = diploma.TeacherID;
            result.Diploma.Tags = diploma.Tags.Select(t => new SelectListItem
            {
                Text = t.Name,
                Disabled = true,
                Selected = true,
                Value = t.Id.ToString()
            });

            var teacher = this.teachers.GetById(diploma.TeacherID).Include(t => t.User).FirstOrDefault();
            result.Diploma.TeacherName = string.Format("{0} {1} {2}", teacher.User.ScienceDegree, teacher.User.FirstName, teacher.User.LastName).Trim();

            var dipl = this.diplomas.GetAll().Where(d => d.IsApprovedByLeader).Select(d => new DiplomaTitleViewModel { Title = d.Title, Id = d.Id }).ToList();

            var duplicates = dipl.Where(d => Infrastructure.StringComparer.CalculateSimilarity(d.Title, result.Diploma.Title) >= 0.65 && d.Id != result.Diploma.Id);
            result.Duplicates = duplicates;
            return this.View(result);
        }
Exemple #2
0
        public ActionResult DownloadFile(int? id)
        {
            if (id == null)
            {
                return this.RedirectToAction("Index", "Home");
            }

            int intId = id ?? 0;
            var diploma = this.diplomas.GetObjectById(intId);
            if (diploma == null)
            {
                this.TempData["Message"] = "Дипломата не бе намерена!";
                return this.RedirectToAction("Index", "Home");
            }

            var result = new StudentDiplomaViewModel();

            var studentDetails = this.students.GetAll()
                                              .Where(s => s.SelectedDiploma.Id == diploma.Id)
                                              .Include(s => s.User)
                                              .To<SimpleStudentViewModel>()
                                              .FirstOrDefault();
            result.Student = studentDetails;

            if (result.Student != null)
            {
                if (string.IsNullOrEmpty(result.Student.Address) || string.IsNullOrEmpty(result.Student.Email)
                    || string.IsNullOrEmpty(result.Student.FirstName) || string.IsNullOrEmpty(result.Student.MiddleName)
                    || string.IsNullOrEmpty(result.Student.LastName) || string.IsNullOrEmpty(result.Student.PhoneNumber)
                    || result.Student.FNumber == 0)
                {
                    return this.RedirectToAction("Index", "Home");
                }
            }
            else
            {
                return this.RedirectToAction("Index", "Home");
            }

            var diplomaModel = this.diplomas.GetAll()
                                             .Where(d => d.Id == intId)
                                             .Include(d => d.Teacher)
                                             .Include(d => d.Tags)
                                             .To<DisplayDiplomaViewModel>();

            result.Diploma = diplomaModel.FirstOrDefault();
            result.Diploma.ContentCSV = diploma.ContentCSV.Split(new char[] { GlobalConstants.ContentSeparator }, System.StringSplitOptions.RemoveEmptyEntries).ToList();
            result.Diploma.TeacherID = diploma.TeacherID;
            result.Diploma.Tags = diploma.Tags.Select(t => new SelectListItem
            {
                Text = t.Name,
                Disabled = true,
                Selected = true,
                Value = t.Id.ToString()
            });

            var teacher = this.teachers.GetById(diploma.TeacherID).Include(t => t.User).FirstOrDefault();
            result.Diploma.TeacherName = string.Format("{0} {1}. {2}", teacher.User.ScienceDegree, teacher.User.FirstName[0], teacher.User.LastName).Trim();

            if (result.Diploma != null)
            {
                if (result.Diploma.ContentCSV.Count == 0 || string.IsNullOrEmpty(result.Diploma.ExperimentalPart)
                    || result.Diploma.Tags.Count() == 0 || string.IsNullOrEmpty(result.Diploma.TeacherName)
                    || string.IsNullOrEmpty(result.Diploma.Title) || string.IsNullOrEmpty(result.Diploma.ModifiedOn.ToString()))
                {
                    return this.RedirectToAction("Index", "Home");
                }
            }
            else
            {
                return this.RedirectToAction("Index", "Home");
            }

            Dictionary<string, string> proparties = new Dictionary<string, string>();

            proparties.Add("[USER_NAME]", string.Format("{0} {1} {2} {3}", result.Student.ScienceDegree, result.Student.FirstName, result.Student.MiddleName, result.Student.LastName));
            proparties.Add("[USER_FNUMBER]", result.Student.FNumber.ToString());
            proparties.Add("[USER_ADDRESS]", result.Student.Address);
            proparties.Add("[USER_TEL]", result.Student.PhoneNumber);
            proparties.Add("[USER_EMAIL]", result.Student.Email);
            proparties.Add("[DOC_TITLE]", result.Diploma.Title.ToString());
            proparties.Add("[DOC_BEGINDATE]", result.Diploma.ModifiedOn.Value.ToString("dd/MM/yyyy"));
            proparties.Add("[DOC_ENDDATA]", result.Diploma.ModifiedOn.Value.AddYears(1).ToString("dd/MM/yyyy"));
            proparties.Add("[DOC_EXP]", result.Diploma.ExperimentalPart);
            proparties.Add("[TEACHER]", result.Diploma.TeacherName);
            proparties.Add("[CONSULTANT]", string.Empty);
            proparties.Add("[DEP_HEAD]", "доц. д-р М. Лазарова");
            proparties.Add("[DEAN]", "проф. д-р Д. Гоцева");

            int i = 1;
            foreach (var item in result.Diploma.ContentCSV)
            {
                string placeHolder = string.Format("[DOC_{0}]", i);
                proparties.Add(placeHolder, string.Format("{0}. {1}", i++, item));
            }

            while (i <= 8)
            {
                string placeHolder = string.Format("[DOC_{0}]", i++);
                proparties.Add(placeHolder, string.Empty);
            }

            StringBuilder tags = new StringBuilder();

            foreach (var tag in result.Diploma.Tags)
            {
                tags.Append(tag.Text + ", ");
            }

            string tagsString = tags.Remove(tags.Length - 2, 2).ToString();

            proparties.Add("[DOC_TECH]", tagsString.ToString());

            var filePath = DocXGenerator.Generate(proparties, this.Server.MapPath("~/Content/DocxFiles/Templates/DiplomaTemplate.docx"));
            var fileName = string.Format("{0}.docx", proparties["[USER_FNUMBER]"]);
            return this.File(filePath, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", fileName);
        }
        public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return this.RedirectToAction("Index", "ManageDiplomas");
            }

            int intId = id ?? 0;
            var diploma = this.diplomas.GetObjectById(intId);
            if (diploma == null)
            {
                this.TempData["Message"] = "Дипломата не бе намерена!";
                return this.RedirectToAction("Index", "ManageDiplomas");
            }

            var result = new StudentDiplomaViewModel();

            var studentDetails = this.students.GetAll()
                                              .Where(s => s.SelectedDiploma.Id == diploma.Id)
                                              .Include(s => s.User)
                                              .To<SimpleStudentViewModel>()
                                              .FirstOrDefault();
            result.Student = studentDetails;

            var diplomaModel = this.diplomas.GetAll()
                                             .Where(d => d.Id == intId)
                                             .Include(d => d.Teacher)
                                             .Include(d => d.Tags)
                                             .To<DisplayDiplomaViewModel>();

            result.Diploma = diplomaModel.FirstOrDefault();
            result.Diploma.ContentCSV = diploma.ContentCSV.Split(new char[] { GlobalConstants.ContentSeparator }, System.StringSplitOptions.RemoveEmptyEntries).ToList();
            result.Diploma.TeacherID = diploma.TeacherID;
            result.Diploma.Tags = diploma.Tags.Select(t => new SelectListItem
            {
                Text = t.Name,
                Disabled = true,
                Selected = true,
                Value = t.Id.ToString()
            });

            var teacher = this.teachers.GetById(diploma.TeacherID).Include(t => t.User).FirstOrDefault();
            result.Diploma.TeacherName = string.Format("{0} {1} {2}", teacher.User.ScienceDegree, teacher.User.FirstName, teacher.User.LastName).Trim();

            var userId = this.User.Identity.GetUserId();
            var messages = this.messages.GetAll().Where(mes => mes.SelectedDiploma.Id == diploma.Id
                                                            && (mes.ResieverUserId == userId
                                                            || mes.SenderUserId == userId))
                                                            .To<MessageViewModel>().ToList();
            foreach (var message in messages)
            {
                message.SenderUser = this.UserManager.FindById(message.SenderUserId);
                message.ResieverUser = this.UserManager.FindById(message.ResieverUserId);
            }

            result.MessageBox = messages;

            result.CurrentUserId = userId;
            return this.View(result);
        }