Exemple #1
0
        public async Task <IActionResult> Edit(LessonDTO model, IFormFile file)
        {
            var lesson = _lessonService.GetById(Convert.ToInt32(TempData["lessonId"]));

            if (file != null)
            {
                var webRoot = Path.Combine("Uploads", "Documents");
                var path    = Path.Combine(webRoot, file.FileName);
                using (var stream = new FileStream(path, FileMode.Create))
                {
                    await file.CopyToAsync(stream);
                }
                model.Resim = path;
            }
            else
            {
                model.Resim = lesson.Resim;
            }

            model.Guid          = lesson.Guid;
            model.Id            = lesson.Id;
            model.Aktif         = lesson.Aktif;
            model.Silindi       = lesson.Silindi;
            model.EklenmeZamani = lesson.EklenmeZamani;
            model.EkleyenId     = lesson.EkleyenId;

            _lessonService.Update(model);
            return(RedirectToAction("Index"));
        }
        public LessonDTO GetByCourse(int courseId, int pageIndex = 1, int pageSize = 20, string vip = "")
        {
            LessonDTO rst = new LessonDTO();

            rst.Course = _course.GetById(courseId);
            if (rst.Course == null)
            {
                return(null);
            }
            var query = _repository.GetMany(e => e.CourseId == courseId).OrderBy(t => t.Name);

            rst.Pager      = new Paging(query.Count(), pageSize, pageIndex);
            rst.Components = (from s in query.Skip((pageIndex - 1) * pageSize).Take(pageSize)

                              select new LessonComponent()
            {
                Id = s.Id,
                Name = s.Name,
                Description = s.Description,
                ImageUrl = s.ImageUrl,
                CourseId = s.CourseId,
                CourseName = s.Course.Name,
                Grama = s.Grama,
                VideoUrl = (s.IsVip != string.IsNullOrEmpty(vip)) ? s.VideoUrl : "",
                isVip = s.IsVip
            }).ToList();
            return(rst);
        }
        public static List <LessonDTO> GetLessonsListBySubscriptionByStudentIdEndDate(int studentId, string date)
        {
            using (Gymnastics_Studio_DataEntities GSDE = new Gymnastics_Studio_DataEntities())
            {
                List <Lesson>         LessonList            = new List <Lesson>();
                DateTime              Date                  = Convert.ToDateTime(date);
                StudentInSubscription studentInSubscription = new StudentInSubscription();
                studentInSubscription = GSDE.StudentInSubscriptions.Where(x => x.StudentId == studentId && x.StartDate <= Date && x.FinishDate >= Date).FirstOrDefault();
                Subscription subscriptin = new Subscription();
                if (studentInSubscription == default)
                {
                    return(null);
                }
                subscriptin = GSDE.Subscriptions.Where(x => x.Id == studentInSubscription.SubscribtionId).FirstOrDefault();
                var subscription = GSDE.Subscriptions.Where(x => x.Id == subscriptin.Id).FirstOrDefault();
                if (subscriptin.LessonKind == default)
                {
                    return(null);
                }
                string lessonKind = subscriptin.LessonKind;
                LessonList = GSDE.Lessons.Where(x => x.LessonKind == lessonKind).ToList();

                return(LessonDTO.ConvertListToDTO(LessonList));
            }
        }
        public int Update(LessonDTO dto)
        {
            var entity = ModelMapper.Mapper.Map <Lesson>(dto);

            entity.EntityState = EntityState.Modified;
            return(_lessonRepository.Save(entity));
        }
 public IActionResult AddLesson(LessonDTO entity)
 {
     if (entity.StartingDate > DateTime.Now)
     {
         if (entity.EndDate > entity.StartingDate)
         {
             if (ModelState.IsValid)
             {
                 var entities = new Lesson()
                 {
                     LessonName      = entity.LessonName,
                     StartingDate    = entity.StartingDate,
                     EndDate         = entity.EndDate,
                     Price           = entity.Price,
                     TransactionTime = DateTime.Now
                 };
                 _lessonService.Add(entities);
                 return(RedirectToAction("ListLesson"));
             }
             return(View(entity));
         }
         else
         {
             TempData["message"] = "Başlangıç Tarihi Bitiş Tarihinden Sonra olamaz";
             return(new RedirectResult("/Admin/AddLesson"));
         }
     }
     else
     {
         TempData["message"] = "Geçmiş Tarihten Başlayamaz";
         return(new RedirectResult("/Admin/AddLesson"));
     }
 }
Exemple #6
0
        /// <summary>
        /// This static void transform an instructor to an instructorDTO for the ApiService
        /// </summary>
        /// <param name="instructor"></param>
        /// <returns>instructorDTO</returns>
        public static InstructorDTO TransformInstructorToInstructorDTO(Instructor instructor)
        {
            InstructorDTO instructorDTO = new InstructorDTO();


            List <LessonDTO> lessonsDTO = new List <LessonDTO>();

            if (instructor.Lessons != null)
            {
                foreach (Lesson lesson in instructor.Lessons)
                {
                    LessonDTO lessonDTO = new LessonDTO();
                    lessonDTO.courseId  = lesson.CourseID;
                    lessonDTO.day       = lesson.Day.ToString().ToLower();
                    lessonDTO.startHour = lesson.StartHour.ToString("HH'h'mm");
                    lessonDTO.duration  = lesson.EndHour.Subtract(lesson.StartHour).TotalMinutes.ToString();
                    lessonsDTO.Add(lessonDTO);
                }
            }

            instructorDTO.instructorId = instructor.ID;
            instructorDTO.schedule     = lessonsDTO;

            return(instructorDTO);
        }
        public async Task <IActionResult> PutLesson(int id, LessonDTO lessonDTO)
        {
            var lesson = _mapper.Map <LessonDTO, Lesson>(lessonDTO);

            if (id != lesson.Id)
            {
                return(BadRequest());
            }

            _context.Entry(lesson).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LessonExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #8
0
        public async Task <IActionResult> PutLesson([FromRoute] int id, [FromBody] LessonDTO lessonDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var lesson = await _context.Lessons.FirstOrDefaultAsync(l => l.ID == id);

            lesson.TopicId = lessonDto.Topic.ID;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LessonExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #9
0
        public async Task <LessonDTO> GetLessonAsync(int lessonId)
        {
            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Add("Authorization", "Bearer " + _accountProvider.AccountInfo.Token);
                try
                {
                    var respnse = await client.GetAsync(AccountProvider.BASEURL + "/api/Lessons/" + lessonId);

                    if (respnse.StatusCode != HttpStatusCode.OK)
                    {
                        return(null);
                    }

                    var stringResult = await respnse.Content.ReadAsStringAsync();

                    LessonDTO result = JsonConvert.DeserializeObject <LessonDTO>(stringResult);

                    return(result);
                }
                catch (Exception e)
                {
                    return(null);
                }
            }
        }
Exemple #10
0
        internal async Task <LessonDTO> UpdateLessonAsync(Guid id, LessonDTO lessonDTO)
        {
            var lessonsDB = await _context.Lesson.Include(c => c.Lectural)
                            .Include(s => s.LessonTypeDB)
                            .Include(s => s.Discipline)
                            .FirstOrDefaultAsync();

            if (lessonsDB == null || lessonDTO.id != id || lessonDTO.lecturalId == null || lessonDTO.disciplineId == null)
            {
                return(null);
            }

            lessonsDB = await ModifyLesson(lessonsDB, lessonDTO);

            _context.Entry(lessonsDB).State = EntityState.Modified;
            try
            {
                await _context.SaveChangesAsync();

                return(lessonDTO);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LessonDTOExists(id))
                {
                    return(null);
                }
                else
                {
                    throw;
                }
            }
        }
Exemple #11
0
        internal async Task <LessonDTO> AddlessonAsync(LessonDTO lessonDTO)
        {
            var lectural = await _context.Lectural.Where(c => c.id == lessonDTO.lecturalId).FirstOrDefaultAsync();

            var gr = await _context.Discipline.Where(c => c.name == lessonDTO.disciplineName).FirstOrDefaultAsync();

            var lessonType = await _context.LessonType.Where(c => c.nameOfType == lessonDTO.lessonType).FirstOrDefaultAsync();

            if (gr == null || lectural == null || lessonType == null)
            {
                return(null);
            }
            LessonDB lessonDB = new LessonDB(lectural, gr, lessonType, lessonDTO);

            try
            {
                _context.Lesson.Add(lessonDB);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LessonDTOExists(lessonDB.id))
                {
                    return(null);
                }
                else
                {
                    throw;
                }
            }

            return(lessonDTO);
        }
        public static int AddLesson(LessonDTO LessonDTO)
        {
            try
            {
                using (Gymnastics_Studio_DataEntities context = new Gymnastics_Studio_DataEntities())
                {
                    Lesson Lesson = new Lesson();
                    Lesson.Name          = LessonDTO.Name?.TrimStart().TrimEnd();
                    Lesson.Day           = LessonDTO.Day?.TrimStart().TrimEnd();
                    Lesson.StartHower    = LessonDTO.StartHower?.TrimStart().TrimEnd();
                    Lesson.FinishHower   = LessonDTO.FinishHower?.TrimStart().TrimEnd();
                    Lesson.MaxStudensNum = LessonDTO.MaxStudensNum;
                    Lesson.LessonKind    = LessonDTO.LessonKind?.TrimStart().TrimEnd();
                    Lesson.TeacherId     = LessonDTO.TeacherId;

                    context.Lessons.Add(Lesson);
                    context.SaveChanges();
                    return(context.Lessons.Max(o => o.Id));
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public async Task <ActionResult <LessonDTO> > PostLesson(LessonDTO lessonDTO)
        {
            var lesson = _mapper.Map <LessonDTO, Lesson>(lessonDTO);

            _context.Lessons.Add(lesson);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetLesson", new { id = lesson.Id }, lesson));
        }
 public static LessonDTO GetLessonDetailsByLessonId(int id)
 {
     using (Gymnastics_Studio_DataEntities GSDE = new Gymnastics_Studio_DataEntities())
     {
         Lesson Lesson = new Lesson();
         Lesson = GSDE.Lessons.FirstOrDefault(x => x.Id == id);
         return(LessonDTO.ConvertToDTO(Lesson));
     }
 }
 public static List <LessonDTO> getLessonList()
 {
     using (Gymnastics_Studio_DataEntities GSDE = new Gymnastics_Studio_DataEntities())
     {
         List <Lesson> LessonList = new List <Lesson>();
         LessonList = GSDE.Lessons.ToList();
         return(LessonDTO.ConvertListToDTO(LessonList));
     }
 }
Exemple #16
0
        public ActionResult Index()
        {
            var LesData = new LessonDTO()
            {
                LessonList = db.Lessons.ToList()
            };

            return(View(LesData));
        }
Exemple #17
0
        private async Task <LessonDB> ModifyLesson(LessonDB lessonDB, LessonDTO lessonDTO)
        {
            lessonDB.id              = lessonDTO.id;
            lessonDB.countHours      = lessonDTO.countHours;
            lessonDB.name            = lessonDTO.name;
            lessonDB.pathToMaterials = lessonDTO.pathToMaterials;
            lessonDB.sectionName     = lessonDTO.sectionName;
            lessonDB.themeName       = lessonDTO.themeName;


            if (lessonDB.Discipline != null)
            {
                if (lessonDB.Discipline.id != lessonDTO.disciplineId)
                {
                    DisciplineDB disciplineDB = await _context.Discipline.Where(c => c.id == lessonDTO.disciplineId).FirstOrDefaultAsync();

                    lessonDB.Discipline = disciplineDB;
                }
            }
            else
            {
                DisciplineDB disciplineDB = await _context.Discipline.Where(c => c.id == lessonDTO.disciplineId).FirstOrDefaultAsync();

                lessonDB.Discipline = disciplineDB;
            }
            if (lessonDB.Lectural != null)
            {
                if (lessonDB.Lectural.id != lessonDTO.lecturalId)
                {
                    Lectural lectural = await _context.Lectural.Where(c => c.id == lessonDTO.lecturalId).FirstOrDefaultAsync();

                    lessonDB.Lectural = lectural;
                }
            }
            else
            {
                Lectural lectural = await _context.Lectural.Where(c => c.id == lessonDTO.lecturalId).FirstOrDefaultAsync();

                lessonDB.Lectural = lectural;
            }

            if (lessonDB.LessonTypeDB != null)
            {
                if (lessonDB.LessonTypeDB.nameOfType != lessonDTO.lessonType)
                {
                    LessonTypeDB type = _context.LessonType.Where(c => c.nameOfType == lessonDTO.lessonType).FirstOrDefault();
                    lessonDB.LessonTypeDB = type;
                }
            }
            else
            {
                LessonTypeDB type = _context.LessonType.Where(c => c.nameOfType == lessonDTO.lessonType).FirstOrDefault();
                lessonDB.LessonTypeDB = type;
            }
            return(lessonDB);
        }
Exemple #18
0
        public ActionResult Edit(int id)
        {
            var dataLes = new LessonDTO()
            {
                LessonList = db.Lessons.ToList(),
                LessonData = db.Lessons.FirstOrDefault(a => a.Id == id)
            };

            return(View("Index", dataLes));
        }
        public LessonDTO Get(int pageIndex = 1, int pageSize = 20)
        {
            LessonDTO rst = new LessonDTO();

            try
            {
                rst = _lesson.GetAll(pageIndex, pageSize);
            }
            catch (Exception ex) { Console.WriteLine(ex.StackTrace); }
            return(rst);
        }
Exemple #20
0
        internal async Task <LessonDTO> GetLessonByIdAsync(Guid id)
        {
            var lessonsDB = await _context.Lesson.Include(c => c.Lectural)
                            .Include(s => s.LessonTypeDB)
                            .Include(s => s.Discipline)
                            .FirstOrDefaultAsync();

            LessonDTO lessonDTO = new LessonDTO(lessonsDB);

            return(lessonDTO);
        }
Exemple #21
0
        public virtual ActionResult CreateLesson(LessonDTO lesson)
        {
            var entity = Mapper.Map <Lesson>(lesson);

            if (lesson.start >= DateTime.Now)
            {
                LessonsService.Add(entity, System.Web.HttpContext.Current.User.Identity.GetUserId());
                return(Json(true));
            }
            return(Json(false));
        }
Exemple #22
0
        public static LessonDTO GetLessonDTO(Lesson Lesson)
        {
            LessonDTO LessonDTO = new LessonDTO();

            LessonDTO.LessonId       = Lesson.LessonId;
            LessonDTO.ScheduleId     = Lesson.ScheduleId;
            LessonDTO.Date           = Lesson.Date;
            LessonDTO.LessonDescribe = Lesson.LessonDescribe;
            LessonDTO.H_W            = Lesson.H_W;

            return(LessonDTO);
        }
Exemple #23
0
        public async Task CreateLesson(LessonDTO lessonDto)
        {
            if (lessonDto == null)
            {
                throw new ArgumentNullException("Input cannot be empty");
            }

            Lesson lesson = Mapper.Map <LessonDTO, Lesson>(lessonDto);

            _database.Lessons.Create(lesson);
            await _database.SaveAsync();
        }
        public IActionResult EditLesson(LessonDTO entity)
        {
            var model = _lessonService.GetById(entity.Id);

            model.LessonName   = entity.LessonName;
            model.StartingDate = entity.StartingDate;
            model.EndDate      = entity.EndDate;
            model.Price        = entity.Price;

            _lessonService.Update(model);
            return(RedirectToAction("ListLesson"));
        }
Exemple #25
0
        public bool DeleteLesson(int id)
        {
            LessonDTO delete = lessons.Where(p => p.LessonId == id).First();

            if (delete == null)
            {
                return(false);
            }
            lessons.Remove(delete);
            tt.LessonRepository.Remove(Mappers.ModelMapper.LessonMapper_toEntity(delete));
            tt.Save();
            return(true);
        }
Exemple #26
0
        public LessonDTO GetLesson(string lessonName)
        {
            Lesson lesson = _database.Lessons.GetOne(x => x.Name == lessonName);

            if (lesson == null)
            {
                throw new ArgumentNullException($"Lesson with such name does not exist. Name: {lessonName}");
            }

            LessonDTO lessonDto = Mapper.Map <Lesson, LessonDTO>(lesson);

            return(lessonDto);
        }
Exemple #27
0
        public IActionResult AddLesson(LessonDTO lessonDTO)
        {
            var teacherId = User.Claims.Where(c => c.Type == ClaimTypes.NameIdentifier)
                            .Select(c => c.Value).SingleOrDefault();
            var lesson = new Lesson
            {
                Name      = lessonDTO.Lesson,
                Period    = lessonDTO.Period,
                TeacherId = Convert.ToInt32(teacherId),
                Year      = lessonDTO.Year
            };

            _lessonService.AddLesson(lesson);
            return(RedirectToAction("Index"));
        }
Exemple #28
0
        internal async Task <LessonDTO> DeleteLessonAsync(Guid id)
        {
            var lessonDb = await _context.Lesson.FindAsync(id);

            if (lessonDb == null)
            {
                return(null);
            }
            _context.Lesson.Remove(lessonDb);
            await _context.SaveChangesAsync();

            LessonDTO lesson = new LessonDTO(lessonDb);

            return(lesson);
        }
Exemple #29
0
        public void testInitialize()
        {
            Debug.WriteLine("Test initialize");
            kern.Get <CoreTimetable>();
            ld            = new LessonDTO();
            ld.auditory   = 6.104;
            ld.day        = 1;
            ld.discipline = "Mathematic";
            ld.group      = "219";
            ld.LessonId   = 1;
            ld.teacher    = "Valera";

            ct.CreateLesson(ld);
            ldl.Add(ld);
        }
Exemple #30
0
        public async Task EditLesson(LessonDTO lessonDto)
        {
            Lesson checkLesson = _database.Lessons.GetOne(x => x.Id == lessonDto.Id);

            if (checkLesson == null)
            {
                throw new ArgumentNullException("Lesson does not exist");
            }

            lessonDto.Id = checkLesson.Id;

            Lesson lesson = Mapper.Map <LessonDTO, Lesson>(lessonDto);

            _database.Lessons.Update(lesson);
            await _database.SaveAsync();
        }