Ejemplo n.º 1
0
 public void Update(LessonDTOPatch lesson)
 {
     if (lesson.StartTime != StartTime && lesson.StartTime != null)
     {
         StartTime = lesson.StartTime;
     }
     if (lesson.EndTime != EndTime && lesson.EndTime != null)
     {
         EndTime = lesson.EndTime;
     }
     if (lesson.Title != Title && lesson.Title != null)
     {
         Title = lesson.Title;
     }
     if (lesson.Audience != Audience && lesson.Audience != null)
     {
         Audience = lesson.Audience;
     }
     if (lesson.Teacher != Teacher && lesson.Teacher != null)
     {
         Teacher = lesson.Teacher;
     }
     if (lesson.Type != Type && lesson.Type != null)
     {
         Type = lesson.Type;
     }
 }
Ejemplo n.º 2
0
        public IActionResult Patch(string date, Guid id, bool all, [FromForm] LessonDTOPatch value)
        {
            var parseDate = new List <int>();
            //var dateTime = new DateTime(parseDate[0], parseDate[1], parseDate[2]);
            var dateTime = new DateTime();

            try
            {
                parseDate = date.Split('-', '/', '\\', '.', '_', ':').Select(e => int.Parse(e)).ToList();
                dateTime  = new DateTime(parseDate[0], parseDate[1], parseDate[2]);
            }
            catch (Exception e)
            {
                return(UnprocessableEntity("Invalid format of date: " + e.Message));
            }
            var delete = Builders <ScheduleDay> .Update.PullFilter(d => d.Lessons, l => l.Id == id);

            var currUser = usersCollection.Find(u => u.Id == Guid.Parse(HttpContext.Session.GetString("userId"))).FirstOrDefault();

            var day = schedulesCollection.Find(n => n.DayDate == dateTime && n.GroupId == currUser.GroupId).FirstOrDefault();

            if (day == null)
            {
                return(NotFound("Lesson with this id not found"));
            }
            var lesson = day.Lessons.Where(l => l.Id == id).FirstOrDefault();

            if (lesson == null)
            {
                return(NotFound("Lesson with this id not found"));
            }
            lesson.Update(value);

            var push = Builders <ScheduleDay> .Update.Push(d => d.Lessons, lesson);

            if (all)
            {
                UpdateAll(lesson, delete, false, currUser.GroupId);
                UpdateAll(lesson, push, false, currUser.GroupId);
            }
            else
            {
                schedulesCollection.UpdateOne(n => n.DayDate == dateTime && n.GroupId == currUser.GroupId, delete);
                schedulesCollection.UpdateOne(n => n.DayDate == dateTime && n.GroupId == currUser.GroupId, push);
            }
            return(new ObjectResult(lesson));
        }