예제 #1
0
        public async Task <ActionResult> CreateProfile(ProfileModel model)
        {
            if (ModelState.IsValid)
            {
                var file = new BinaryFile()
                {
                    Name        = model.Photo.FileName,
                    Content     = model.Photo.InputStream.ToByteArray(),
                    ContentType = model.Photo.ContentType
                };

                Candidate candidate = new Candidate
                {
                    DateofBirth = model.DateOfBirth,
                    Name        = model.Name,
                    User        = await userManager.FindByIdAsync(Convert.ToInt64(User.Identity.GetUserId())),
                    Experience  = model.Experience.ToList(),
                    Avatar      = file
                };
                try
                {
                    jobseekerRepository.Save(candidate);
                    return(RedirectToAction("Main", "Jobseeker"));
                }
                catch
                {
                    //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Record Inserted Successfully')", true);
                    return(RedirectToAction("Main", "Jobseeker"));
                }
            }
            return(RedirectToAction("Main", "Jobseeker")); //добавить оповещения
        }
예제 #2
0
 public async Task <ActionResult> CreateProfile(ProfileModel model)
 {
     if (ModelState.IsValid)
     {
         var path = AppDomain.CurrentDomain.BaseDirectory;
         var file = new BinaryFile();
         if (model.Photo != null)
         {
             file = new BinaryFile
             {
                 Name        = DateTime.Now.ToString().Replace("/", "_").Replace(":", "_") + model.Photo.FileName,
                 Path        = Path.Combine(path, @"App_Data\Files", DateTime.Now.ToString().Replace("/", "_").Replace(":", "_") + model.Photo.FileName),
                 ContentType = model.Photo.ContentType
             };
             if (!Directory.Exists(file.Path))
             {
                 Directory.CreateDirectory(Path.Combine(path, @"App_Data\Files"));
             }
             using (var fileStream = System.IO.File.Create(file.Path))
             {
                 model.Photo.InputStream.Seek(0, System.IO.SeekOrigin.Begin);
                 model.Photo.InputStream.CopyTo(fileStream);
             }
             fileRepository.Save(file);
         }
         List <long> IdList = new List <long>();
         if (model.NewExperience != null)
         {
             IdList.AddRange(experienceRepository.CreateNewExperience(model.NewExperience));
         }
         if (model.NewExperience == null && model.SelectedExperience == null)
         {
             IdList.AddRange(experienceRepository.CreateNewExperience("Без опыта"));
         }
         if (model.SelectedExperience != null)
         {
             foreach (var e in model.SelectedExperience)
             {
                 IdList.Add(Convert.ToInt64(e));
             }
         }
         Candidate candidate = new Candidate
         {
             DateofBirth = model.DateOfBirth,
             Name        = model.Name,
             Experience  = experienceRepository.GetSelectedExperience(IdList),
             User        = UserManager.FindById(Convert.ToInt64(User.Identity.GetUserId())),
             Avatar      = file
         };
         try
         {
             jobseekerRepository.Save(candidate);
             return(RedirectToAction("Main", "Jobseeker"));
         }
         catch
         {
             //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Record Inserted Successfully')", true);
             return(RedirectToAction("Main", "Jobseeker"));
         }
     }
     return(RedirectToAction("Main", "Jobseeker")); //добавить оповещения
 }