Пример #1
0
        public async Task <IActionResult> DeleteFiles(string[] photosIds)
        {
            List <Fotografia> photos = new List <Fotografia>();

            foreach (string photoId in photosIds)
            {
                #region Transformar photoId(string) em int32
                int id = 0;
                try
                {
                    id = Int32.Parse(photoId);
                }
                catch (Exception e)
                {
                    await _logger.LogError(
                        descricao : "Erro ao transformar string em int32.",
                        classe : "GaleriasController",
                        metodo : "DeleteFiles",
                        erro : e.Message
                        );
                }
                #endregion

                Fotografia photo = await _context.Fotografias.Include(f => f.ContaOnedrive).Where(f => f.ID == id).FirstOrDefaultAsync();

                if (photo != null)
                {
                    photos.Add(photo);
                }
            }

            if (photos.Count() > 0)
            {
                if (await _onedrive.DeleteFilesAsync(photos))
                {
                    return(Json(new { success = true }));
                }
            }

            return(Json(new { success = false }));
        }