public async Task CreateAsync(CreatePictureInputModel input, string userId, string imagePath) { // /wwwroot/images/recipes/jhdsi-343g3h453-=g34g.jpg Directory.CreateDirectory($"{imagePath}/recipes/"); foreach (var image in input.Images) { var extension = Path.GetExtension(image.FileName).TrimStart('.'); if (!this.allowedExtensions.Any(x => extension.EndsWith(x))) { throw new Exception($"Invalid image extension {extension}"); } var dbImage = new CustomerPhoto { UserId = userId, Extension = extension, CigarId = input.CigarId, PhotoText = input.PhotoText, }; await this.photosEntity.AddAsync(dbImage); var physicalPath = $"{imagePath}/CustomerPhotos/{dbImage.Id}.{extension}"; using Stream fileStream = new FileStream(physicalPath, FileMode.Create); await image.CopyToAsync(fileStream); } await this.photosEntity.SaveChangesAsync(); }
private async Task PersistCustomerPhoto(CustomerPhoto customerPhoto) { await PhotoController.SaveAsync(customerPhoto); _personRegistrationInfo.Photos.Add(customerPhoto); this.RefreshList(); }
private async Task LoadCustomerPhoto(string nationalId) { CustomerPhotoService service = new CustomerPhotoService(); CustomerPhoto photo = await service.GetMostRecentCustomerPhoto(nationalId); CustomerDetailFragmentViewModel vm = this.ViewModel as CustomerDetailFragmentViewModel; if (photo == null || photo.FilePath == null || vm == null) { return; } vm.MostRecentPhoto = photo.FilePath; try { Bitmap bitmap = BitmapFactory.DecodeFile(photo.FilePath); if (bitmap == null) { return; } this.Activity.RunOnUiThread(() => { this._imgCustomerPhoto.SetImageBitmap(bitmap); }); } catch (Exception ex) { Logger.Error(ex); } }
private async void AdapterOnPhotoUpdated(object sender, CustomerPhotoUpdatedEvent e) { CustomerPhotoViewModel vm = this.ViewModel as CustomerPhotoViewModel; if (vm == null) { return; } vm.PhotoUpdated(e.Position); // serialize the selected photo and pass it's string to the Photo Upload service CustomerPhoto photo = vm.CustomerPhotos[e.Position]; var photoList = new List <CustomerPhoto> { photo }; var photoListString = JsonConvert.SerializeObject(photoList); Logger.Verbose(photoListString); var photoUploadServiceIntent = new Intent(Activity, typeof(CustomerPhotoUploadService)); photoUploadServiceIntent.PutExtra(CustomerPhotoUploadService.PhotoList, photoListString); Activity.StartService(photoUploadServiceIntent); }
public async void PhotoUpdated(int position, PhotoUploadStatus newStatus = PhotoUploadStatus.Pending) { CustomerPhotoController controller = new CustomerPhotoController(); CustomerPhoto photo = this.CustomerPhotos[position]; photo.PhotoUploadStatus = newStatus; await controller.SaveAsync(photo); CustomerPhoto backUpPhoto = new CustomerPhoto { CustomerIdentifier = this.CustomerPhotos[position].CustomerIdentifier, FilePath = this.CustomerPhotos[position].FilePath, Phone = this.CustomerPhotos[position].Phone, PhotoStatus = this.CustomerPhotos[position].PhotoStatus, PhotoUploadStatus = this.CustomerPhotos[position].PhotoUploadStatus, TypeOfPhoto = this.CustomerPhotos[position].TypeOfPhoto, Id = this.CustomerPhotos[position].Id, Created = this.CustomerPhotos[position].Created, Modified = this.CustomerPhotos[position].Modified }; this.CustomerPhotos.RemoveAt(position); this.CustomerPhotos.Insert(position, backUpPhoto); this.RaisePropertyChanged(() => this.CustomerPhotos); }
public void RemovePhoto(CustomerPhoto photo) { if (this._personRegistrationInfo.Photos == null) { return; } this._personRegistrationInfo.Photos.Remove(photo); }
public async Task <Dictionary <Guid, PhotoUploadStatus> > UploadPhoto(CustomerPhoto customerPhoto) { //add the passed photo var photos = new List <CustomerPhoto> { customerPhoto }; var photoUploadStatusDict = await Upload(photos); return(photoUploadStatusDict); }
public void PhotoUpdated(CustomerPhoto newPhoto) { int position = -1; for (int i = 0; i < this.CustomerPhotos.Count; i++) { if (this.CustomerPhotos[i].Id == newPhoto.Id) { position = i; break; } } this.PhotoUpdated(position, newPhoto.PhotoUploadStatus); }
public ActionResult Index() { var tempEmail = System.Web.HttpContext.Current.User.Identity.GetUserName().ToString(); var currentUser = (from user in db.Users where user.Email.Equals(tempEmail) select new { user.FirstName }).ToList(); foreach (var user in currentUser) { ViewBag.ViewName = user.FirstName; } ViewBag.ZipFilesList = getZipfileListAll(); ViewBag.ZipFilesListUser = getZipfileList(tempEmail); List <CustomerPhoto> CustomerPhotoList = new List <CustomerPhoto>(); // to hold list of ProductPicture and Customer details var BookList = (from cust in db.Users join pic in db.PurchasedPhotoes on cust.Id equals pic.Customer_Id select new { cust.FirstName, cust.LastName, cust.Email, pic.PurchasedPic_Id, pic.Title, pic.Picture, }).ToList(); //query getting data from database from joining two tables and storing data in CustomerPhotoList foreach (var item in BookList) { CustomerPhoto obj = new CustomerPhoto(); // ViewModel obj.Customer_Email = item.Email; obj.Picture_Id = item.PurchasedPic_Id; obj.Customer_Name = item.FirstName + " " + item.LastName; obj.Title = item.Title; obj.Picture = item.Picture; CustomerPhotoList.Add(obj); } //Using foreach loop fill data from StoreDetailList to List<CustomerPhoto>. ViewBag.ListPhoto = CustomerPhotoList; return(View(CustomerPhotoList)); //List of CustomerPhotoList }
private async Task HandleCameraRequest(File file) { _log.Verbose("HandleCameraRequest"); string path = null; try { // Resize the image path = LoadAndResizeBitmap(file, _photoWidth, _photoHeight); } catch (OutOfMemoryError e) { GC.Collect(); _log.Verbose("Oops, Got an OutOfMemoryError when loading image"); _log.Error(e); } catch (Exception e) { _log.Verbose("Oops, Got an Exception when loading image"); _log.Error(e); } if (path != null) { _log.Verbose("Created bitmap successfully"); CustomerPhoto photo = new CustomerPhoto { FilePath = path, TypeOfPhoto = _personRegistrationInfo.TypeOfPhotoBeingTaken, PhotoStatus = PhotoSaveStatus.Successful, PhotoUploadStatus = PhotoUploadStatus.OnHold, CustomerIdentifier = _personRegistrationInfo.NationalId, Phone = _personRegistrationInfo.Phone }; // saving to db only if the photo file actually exists await PersistCustomerPhoto(photo); this._photoListAdapter.AddItem(photo); } else { _log.Verbose("Oh crap, Creating bitmap failed"); FailedTakingPhoto(); } }
private void UploadStatusEvent(object sender, UploadStatusEventArgs e) { CustomerPhotoViewModel vm = this.ViewModel as CustomerPhotoViewModel; if (e.PhotoUploadStatusDictionary == null || vm == null) { return; } foreach (var map in e.PhotoUploadStatusDictionary) { CustomerPhoto photo = new CustomerPhoto { Id = map.Key, PhotoUploadStatus = map.Value }; vm.PhotoUpdated(photo); } }
private async Task <Dictionary <Guid, PhotoUploadStatus> > Upload(List <CustomerPhoto> photos) { var photoUploadStatusDict = new Dictionary <Guid, PhotoUploadStatus>(); CustomerPhoto currentPhotoForUpload = null; PhotoUploadStatus photoUploadStatus = PhotoUploadStatus.Pending; try { if (_connectivityService.HasConnection() && photos.Any()) { Logger.Verbose("Total number of Photos available " + photos.Count); // loop through existing customer photos, if any foreach (var photo in photos) { currentPhotoForUpload = photo; photoUploadStatus = photo.PhotoUploadStatus; var photoName = Path.GetFileName(currentPhotoForUpload.FilePath); Logger.Verbose("About to process Photo : " + photoName); Logger.Verbose("DSR Country Code"); Logger.Verbose(Settings.Instance.DsrCountryCode.ToString().ToLower()); // build up a blob name that includes the phone and national id number of the customer as well as country prefix var blobName = currentPhotoForUpload.Phone + "_" + currentPhotoForUpload.CustomerIdentifier + "_" + Settings.Instance.DsrCountryCode.ToString().ToLower() + "_" + Path.GetFileName(photoName); var blockBlob = _photoBlobContainer.GetBlockBlobReference(Path.GetFileName(blobName)); // set the metadata of the blob to have customer's national id, type and description of photo if (!string.IsNullOrEmpty(currentPhotoForUpload.CustomerIdentifier)) { blockBlob.Metadata["NationalID"] = currentPhotoForUpload.CustomerIdentifier; } if (!string.IsNullOrEmpty(currentPhotoForUpload.Phone)) { blockBlob.Metadata["PhoneNumber"] = currentPhotoForUpload.Phone; } if (currentPhotoForUpload.TypeOfPhoto > 0) { blockBlob.Metadata["PhotoType"] = currentPhotoForUpload.TypeOfPhoto.ToString(); } // upload each photo to Azure Blob Storage if (File.Exists(currentPhotoForUpload.FilePath)) { using (var fileStream = File.OpenRead(currentPhotoForUpload.FilePath)) { await blockBlob.UploadFromStreamAsync(fileStream); Logger.Verbose("Photo uploaded to Azure Blob Storage : " + blobName); } } // set the upload status to success photoUploadStatus = PhotoUploadStatus.Successfull; // save the photo's status to the database currentPhotoForUpload.PhotoUploadStatus = photoUploadStatus; await _photoController.SaveAsync(currentPhotoForUpload); // update the photo status dictionary photoUploadStatusDict.Add(currentPhotoForUpload.Id, currentPhotoForUpload.PhotoUploadStatus); Logger.Verbose("Updated Customer Photo Status to Success"); } } } catch (StorageException se) { Logger.Verbose("StorgeException Caught On Photo Upload"); // set the upload status to Fail photoUploadStatus = PhotoUploadStatus.Failed; var requestInformation = se.RequestInformation; var errorCode = requestInformation.ExtendedErrorInformation.ErrorCode; var statusCode = (HttpStatusCode)requestInformation.HttpStatusCode; Logger.Verbose(errorCode); Logger.Verbose(statusCode.ToString()); // if it is an authentication failure then it means the SAS Token has probably expired and a new one is needed if (errorCode == StorageErrorCodeStrings.AuthenticationFailed) { // SAS Token probably has expired Logger.Verbose("SAS Token Expired"); // TODO Add code to request new SAS Token from OTA Settings or API Call } } catch (Exception e) { Logger.Verbose("General Exception Caught On Photo Upload"); Logger.Verbose(e.Message); // set the upload status to Fail photoUploadStatus = PhotoUploadStatus.Failed; Logger.Error(e); } try { // if the upload failed, update the database accordingly, but from another try/catch block if (photoUploadStatus == PhotoUploadStatus.Failed && currentPhotoForUpload != null) { currentPhotoForUpload.PhotoUploadStatus = photoUploadStatus; await _photoController.SaveAsync(currentPhotoForUpload); // update the photo status dictionary photoUploadStatusDict.Add(currentPhotoForUpload.Id, currentPhotoForUpload.PhotoUploadStatus); Logger.Verbose("Updated Customer Photo Status to Failed"); } } catch (Exception dbe) { Logger.Verbose("General Exception Caught In CustomerPhoto Table Updated on Failed Upload"); Logger.Verbose(dbe); Logger.Error(dbe); } return(photoUploadStatusDict); }