public async Task<ActionResult> Register(CadetRegistration cadet)
 {
     if (cadet != null)
     {
         var result = await RegisterService.RegisterCadet(cadet);
         if (result != null)
         {
             return View("RegisterSuccess", result);
         }
     }
     return HttpNotFound();
 }
Beispiel #2
0
        public async Task<CadetLogin> RegisterCadet(CadetRegistration cadet)
        {
            if (cadet != null)
            {
                string login = Transliter.Translite(cadet.Name) + cadet.BirthDay.ToShortDateString().Replace(".", "");
                string password = Transliter.GeneratePassword();

                var trPr = await _context.TrainingPrograms.GetAsync(cadet.TrainingProgram);
                Cadet cadetAdd = new Cadet
                {
                    Name = cadet.Name,
                    LastName = cadet.LastName,
                    MiddleName = cadet.MiddleName,
                    BirthDay = cadet.BirthDay.Date,
                    BirthPlace = cadet.BirthPlace,
                    Registration = cadet.Registration,
                    PassportNumber = cadet.PassportNumber,
                    PassportIssueBy = cadet.PassportIssueBy,
                    PassportNumberId = cadet.PassportNumberId,
                    PassportIssueDate = cadet.PassportIssueDate.Date,
                    MedicalNumber = cadet.MedicalNumber,
                    MedicalName = cadet.MedicalName,
                    MedicalDate = cadet.MedicalDate.Date,
                    Job = cadet.Job,
                    JobPosition = cadet.JobPosition,
                    Nationality = cadet.Nationality,
                    PhoneHome = cadet.PhoneHome,
                    PhoneMobile = cadet.PhoneMobile,
                    Education = cadet.Education,
                    RegistrationDate = DateTime.Now.Date,
                    Enrolled = false,
                    TrainingProgramId = trPr.Id,
                };             
               
                _context.Cadets.Create(cadetAdd);
                int result = await _context.SaveAsync();
                if (result > 0)
                {
                    return new CadetLogin
                    {
                        Username = login,
                        Password = password
                    };
                }
            }
            return null;
        }