Exemple #1
0
 public async Task <TClass> LoadPhoto(TClass existEvent, O2EvPhoto o2EvPhoto)
 {
     DataContext.Attach(o2EvPhoto);
     o2EvPhoto.O2EvEvent = existEvent;
     existEvent.Photos.Add(o2EvPhoto);
     DataContext.O2EvPhoto.Add(o2EvPhoto);
     return(await AddOrUpdateAsync(existEvent));
 }
Exemple #2
0
        private static async Task <O2EvPhoto> PreparePhoto(O2EvEvent existEvent,
                                                           O2EvEventPhotoDto o2EvEventPhotoDto = null)
        {
            const string notImage = "not_image.jpg";
            const string path     = "Files/" + notImage;

            var o2EvPhoto = new O2EvPhoto();

            //load default photo
            if (o2EvEventPhotoDto == null)
            {
                if (!System.IO.File.Exists(path))
                {
                    throw new Exception("File not found - " + path);
                }

                using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read))
                {
                    o2EvPhoto.FileName = existEvent.Id.ToString() + '_' + DateTime.Now.ConvertToUnixTime() +
                                         Path.GetExtension(notImage).ToLower();
                    o2EvPhoto.Url = await AzureBlobHelper.UploadFileToStorage(stream,
                                                                              fileName : o2EvPhoto.FileName,
                                                                              TypeTable.Events);

                    o2EvPhoto.IsMain = true;

                    return(o2EvPhoto);
                }
            }

            //prepare file
            var file = o2EvEventPhotoDto.File;

            if (file.Length > 0)
            {
                using (Stream stream = file.OpenReadStream())
                {
                    o2EvPhoto.Url = await AzureBlobHelper.UploadFileToStorage(stream,
                                                                              existEvent.Id.ToString() + '_' + DateTime.Now.ConvertToUnixTime() +
                                                                              Path.GetExtension(notImage).ToLower(),
                                                                              TypeTable.Events);

                    return(o2EvPhoto);
                }
            }

            throw new Exception("File is empty");
        }