Esempio n. 1
0
        public ActionResult CreateLec()
        {
            var       result = departmentService.GetDepartments().ToList();
            CreateLec res    = new CreateLec {
                departments = result
            };

            ViewBag.CL = "";
            return(View(res));
        }
Esempio n. 2
0
        public async Task <ActionResult> CreateLec(CreateLec createLec, HttpPostedFileBase uploadImage)
        {
            createLec.departments = departmentService.GetDepartments().ToList();
            if (uploadImage == null)
            {
                ModelState.AddModelError("Image", "Add image");
            }
            if (ModelState.IsValid)
            {
                byte[] imageData = null;
                using (var binaryReader = new BinaryReader(uploadImage.InputStream))
                {
                    imageData = binaryReader.ReadBytes(uploadImage.ContentLength);
                }
                createLec.Image = imageData;


                var user = new ApplicationUser {
                    UserName = createLec.FirstName + " " + createLec.SecondName, Email = createLec.LecturerEmail
                };



                var result = await UserManager.CreateAsync(user, createLec.Password);

                if (result.Succeeded)
                {
                    await UserManager.AddToRoleAsync(user.Id, "lecturer");

                    lecturerService.AddLecturer(new BLL.DTOModels.LecturerDTO
                    {
                        FirstName     = createLec.FirstName,
                        SecondName    = createLec.SecondName,
                        LecturerEmail = createLec.LecturerEmail,
                        Image         = createLec.Image,
                        ImageName     = createLec.FirstName + " " + createLec.SecondName,
                        Information   = createLec.Information
                    }, createLec.SelectedDepId);
                    return(Redirect("/Manage/Index"));
                }
                AddErrors(result);
            }
            return(View(createLec));
        }