public IActionResult Create(StudentAdd model)
 {
     if (ModelState.IsValid)
     {
         var files = HttpContext.Request.Form.Files;
         foreach (var Image in files)
         {
             if (Image != null && Image.Length > 0)
             {
                 var          file = Image;
                 MemoryStream ms   = new MemoryStream();
                 file.OpenReadStream().CopyTo(ms);
                 Models.Students.StudentAdd imageEntity = new Models.Students.StudentAdd()
                 {
                     IMG = Convert.ToBase64String(ms.ToArray()),
                 };
                 datamax = imageEntity.IMG;
             }
         }
         model.IMG = datamax;
         try
         {
             var student = new StudentModel()
             {
                 //StudentId = model.StudentId,
                 Name       = model.Name,
                 IMG        = model.IMG,
                 DOB        = model.DOB,
                 Email      = model.Email,
                 Sex        = model.Sex,
                 LanguageId = model.LanguageId,
                 LevelId    = model.LevelId
             };
             _dbContext.Add(student);
             if (_dbContext.SaveChanges() > 0)
             {
                 TempData["Message"] = "Student has been added successfully.";
             }
             else
             {
                 TempData["Message"] = "Something went wrong, please contact administrator.";
             }
         }
         catch (Exception)
         {
             return(View());
         }
     }
     ViewBag.Levels    = GetLevels();
     ViewBag.Languages = GetLanguages();
     return(View(new StudentAdd()));
 }
Ejemplo n.º 2
0
        public IActionResult Create(LevelAdd model)
        {
            if (ModelState.IsValid)
            {
                var level = new LevelModel()
                {
                    LevelName = model.LevelName
                };
                _dbContext.Add(level);
                if (_dbContext.SaveChanges() > 0)
                {
                    TempData["Message"] = "Level has been added successfully.";
                }
                else
                {
                    TempData["Message"] = "Something went wrong, please contact administrator.";
                }
            }

            return(View(new LevelAdd()));
        }