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"); }
private O2EvEvent MappingEvent(O2EvEventForCreateDto o2EvEventForCreateDto) { var list = new O2EvMeta(); // var locationList = _mapper.Map<O2EvMeta>(o2EvEventForCreateDto.Meta); list = new O2EvMeta() { LocationCountry = o2EvEventForCreateDto.Meta.Country, LocationRegion = o2EvEventForCreateDto.Meta.Region }; var o2EvEvent = new O2EvEvent() { Title = o2EvEventForCreateDto.Title, ShortDescription = o2EvEventForCreateDto.ShortDescription, StartDate = o2EvEventForCreateDto.StartDate, EndDate = o2EvEventForCreateDto.EndDate, Meta = list }; return(o2EvEvent); }