Esempio n. 1
0
 private async Task Save(IEnumerable <CalendarListEntry> calendars)
 {
     foreach (var calendar in calendars)
     {
         if (calendar.Id == configuration["Settings:AdminEmail"])
         {
             continue;
         }
         if (calendar.Id.Contains("vietnamese") || calendar.Id.Contains("holiday") || calendar.Id.Contains("contacts"))
         {
             continue;
         }
         FtmCalendarInfo room = new FtmCalendarInfo()
         {
             CalendarId   = calendar.Id,
             CalendarName = calendar.Summary,
             Description  = calendar.Description,
             IsUseable    = true
         };
         context.FtmCalendarInfo.Add(room);
     }
     await context.SaveChangesAsync();
 }
Esempio n. 2
0
        public async Task <IActionResult> UpdateCalendarsUsable([FromBody] IEnumerable <CalendarInfoDto> calendarInfoDto)
        {
            using (var transaction = context.Database.BeginTransaction())
            {
                try
                {
                    if (calendarInfoDto.Count() == 0)
                    {
                        return(BadRequest());
                    }
                    var calendars = context.FtmCalendarInfo.ToArray();

                    foreach (var item in calendarInfoDto)
                    {
                        var update = calendars.First(x => x.CalendarId == item.RoomId);
                        update.IsUseable = item.IsUseable;
                        //update.CalendarName = editedRoom.RoomName;
                        //update.Description = editedRoom.Description;
                    }
                    await context.SaveChangesAsync();

                    transaction.Commit();
                    var result = context.FtmCalendarInfo.Where(x => x.IsUseable).Select(x => new CalendarInfoDto()
                    {
                        RoomId      = x.CalendarId,
                        RoomName    = x.CalendarName,
                        IsUseable   = x.IsUseable,
                        Description = x.Description
                    });
                    return(Ok(result));
                }
                catch
                {
                    return(BadRequest());
                }
            }
        }