public IActionResult CreateClass(string userId, [FromBody] ClassroomDto classroomDetails)
        {
            //        string userId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
            var finalclassroom = Mapper.Map <Classroom>(classroomDetails);

            //        _userInfoRepository.AddUser(finalUser);



            _userInfoRepository.CreateClassroomfunction(userId, finalclassroom);
            if (!_userInfoRepository.Save())
            {
                return(StatusCode(500, "problem"));
            }
            var createdClassroomToReturn = Mapper.Map <Models.ClassroomDto>(finalclassroom);

            // User user = _context.Users.Where(x => x.Id == userId).Include(x => x.EducatorDetails).FirstOrDefault();
            // //Check for null etC
            //user.EducatorDetails.Classrooms.Add(
            //     new Classroom()
            //     {
            //         Name = classroomDetails.Name,
            //         Description = classroomDetails.Description,
            //     }
            //     );
            //user.EducatorDetails.Enrollments.Add(newEnrollment);
            _context.SaveChanges();
            return(Ok(createdClassroomToReturn));
        }
Exemple #2
0
        public async Task <ActionResult <ClassroomDto> > CreateClassroom(
            [FromBody] ClassroomDto classroomDto
            )
        {
            var user = (ApplicationUser)HttpContext.Items["ApplicationUser"];

            Debug.Assert(user != null, nameof(user) + " != null");

            try
            {
                var classroom    = classroomDto.ToClassroom();
                var newClassroom = await _classroomService.CreateAsync(classroom);

                await _classroomService.AddUserAsync(newClassroom, user);

                await _userManager.AddClaimAsync(user, new Claim($"Classroom/{classroom.Id.ToString()}/Owner", "true"));

                return(Ok(newClassroom.ToDto()));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(BadRequest());
            }
        }
        public ActionResult Add()
        {
            var classroomDto = new ClassroomDto
            {
                ClassroomTypes = new SelectList(classroomTypeService.GetClassroomTypes(), "Id", "Type"),
            };

            return(View(classroomDto));
        }
        void BuildClassroom(IList <ClassroomDto> source, VDashboardExam item)
        {
            var classRoom = source.FirstOrDefault(x => x.Id == item.ClassroomId);

            if (classRoom == null)
            {
                classRoom = new ClassroomDto(item.ClassroomId, item.ClassNumber);
                source.Add(classRoom);
            }
            BuildExam(classRoom.Exams, item);
        }
        public IActionResult UpdateClass(string userId, int classroomId, [FromBody] ClassroomDto classDto)
        {
            User usersvariableforclassroom = _context.Users.Where(x => x.Id == userId).Include(x => x.EducatorDetails.Classrooms).FirstOrDefault();
            var  classroom = usersvariableforclassroom.EducatorDetails.Classrooms.Where(x => x.Id == classroomId).FirstOrDefault();

            //ready to patch
            classroom.Name        = classDto.Name;
            classroom.Description = classDto.Description;


            _context.SaveChanges();
            return(Ok());
        }
        public void CreateNewClassroomDto(ClassroomDto classroomDto)
        {
            var classroom = Mapper.Map <Classroom>(classroomDto);

            //var lesson = new Lesson
            //{
            //    Name = lessonDto.Name,
            //    Description = lessonDto.Description,
            //    DepartmentId = lessonDto.DepartmentId,
            //    CreatedDate = DateTime.Now,
            //    CreatedBy = "test"
            //};
            CreateNewClassroom(classroom);
        }
 public ActionResult Update(ClassroomDto model)
 {
     try
     {
         classroomService.UpdateClassroomDto(model);
         var successMessage = $"رشته {model.Name} با موفقیت ثبت شد";
         return(Json(new { success = true, message = successMessage }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         var failMessage = "خطایی در ذخیره رخ داد، لطفا ورود داده را بررسی نمایید";
         failMessage += $".<br /> code {ex.Message}";
         return(Json(new { success = false, message = failMessage }, JsonRequestBehavior.AllowGet));
     }
 }
Exemple #8
0
 public ActionResult Add(ClassroomDto model)
 {
     try
     {
         model.EducationalCenterId = WebUserInfo.SiteId;
         classroomService.CreateNewClassroomDto(model);
         var successMessage = $"رشته {model.Name} با موفقیت ثبت شد";
         return(Json(new { success = true, message = successMessage }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         var failMessage = "خطایی در ذخیره رخ داد، لطفا ورود داده را بررسی نمایید";
         failMessage += $" {ex.Message}";
         return(Json(new { success = false, message = failMessage }, JsonRequestBehavior.AllowGet));
     }
 }
Exemple #9
0
        public static Classroom ToClassroom(this ClassroomDto classroomDto)
        {
            var validId = Guid.TryParse(classroomDto.Id, out var id);

            if (!validId && !string.IsNullOrWhiteSpace(classroomDto.Id))
            {
                throw new Exception("Invalid Classroom.Id");
            }

            return(new Classroom
            {
                Id = id,
                Name = classroomDto.Name,
                JoinCode = new Random().Next(10000, 99999)
            });
        }
        public void UpdateClassroomDto(ClassroomDto classroomDto)
        {
            var classroom = Mapper.Map <Classroom>(classroomDto);

            UpdateClassroom(classroom);
        }