Пример #1
0
        public Cv Add(CvData cv, string rootUrl)
        {
            var cvPoco   = _mapper.Map <Repositories.Pocos.Cv>(cv);
            var newCv    = _cvRepository.Add(cvPoco);
            var mappedCv = _mapper.Map <Cv>(newCv);

            MapCvUrls(mappedCv, rootUrl);
            return(mappedCv);
        }
Пример #2
0
        public ActionResult Export(StripperViewModel model, string submitter)
        {
            if (!ModelState.IsValid)
            {
                //validation failed
                TempData["exportForm"] = model;
                TempData["ViewD"]      = ViewData;
                return(RedirectToAction("Index"));
            }
            if (model.ResultCv == null)
            {
                return(RedirectToAction("Index"));
            }

            CV cv = model.ResultCv;

            //removes any accidental whitespaces at beginning and end of every value in the CV
            cv.TrimEverything();

            //checks if Languages are using simple or detailed input
            cv.SetLanguageSetting();

            try
            {
                //TODO: improve saving, more specific instead of just saving the entire thing in the database as is.
                //Save (for now) the complete CV-model in the Database
                Repo.Add(cv);
                //context.Cvs.Add(cv);
                //context.SaveChanges();
                Repo.SaveChanges();
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage);
                    }
                }
            }

            //checks based on submitter name (which button was pressed) if CV should be anonymous or not
            if (submitter.Equals("Generate Anonymous CV"))
            {
                //requires anonymous PDF
                cv.SetAnonymousCv();
            }

            string resultName = "";

            //set name of generated pdf based on if anonymous and if name contains prefix
            if (cv.IsAnonymous)
            {
                //cv is anonymous so file should be too
                resultName = $"CV_User_{cv.ID}_EHV.pdf";
            }
            else
            {
                if (cv.Prefix == "")
                {
                    resultName = $"CV_{cv.Name}_{cv.Surname}_EHV.pdf";
                }
                else
                {
                    resultName = $"CV_{cv.Name}_{cv.Prefix}_{cv.Surname}_EHV.pdf";
                }
            }

            TempData["pdfName"] = resultName;
            //generate PDF and generate view that shows that PDF instead of redirect to index

            PdfHelper helper = new PdfHelper();

            byte[] newPdf = helper.GeneratePdf(cv);
            TempData["bytes"] = newPdf;

            //and delete temporary file
            System.IO.File.Delete((string)TempData["tempFile"]);

            return(View());
        }
Пример #3
0
 public void CreateCv(Cv cv)
 {
     cvRepository.Add(cv);
 }