public PlantDetailsPhotosPage(Plant plant, PlantPhoto selectedPhoto) { InitializeComponent(); this.BindingContext = new PlantDetailsPhotosViewModel(plant, selectedPhoto, this); vm = this.BindingContext as PlantDetailsPhotosViewModel; }
public void RenameImageAndUsages(PlantPhoto plantPhoto) { var dateString = _now.ToString("yyyy-MM-dd HH:mm:ss.fff"); var fileManager = new TxFileManager(); try { using (var conn = new SqlConnection(_settings.ConnectionString)) using (var scope = new TransactionScope()) { conn.Open(); conn.Execute(_photoUpdateQuery, new { OldPhotoId = plantPhoto.PhotoId, NewPhotoId = plantPhoto.PhotoId.AddTif(), NewUpdatedAt = _now }); conn.Execute(_usageUpdateQuery, new { plantPhoto.PhotoId, NewPhotoId = plantPhoto.PhotoId.AddTif() }); foreach (var imageRoot in _settings.ImageRoots) { var imagePath = plantPhoto.GetActualImagePath(imageRoot); var newPath = plantPhoto.GetReplacementPath(imageRoot, _settings.TargetExtension); if (File.Exists(imagePath)) { fileManager.Move(imagePath, newPath); } } foreach (var thumbnailRoot in _settings.ThumbnailRoots) { var thumbPath = plantPhoto.GetThumbnailPath(thumbnailRoot); var newPath = plantPhoto.GetReplacementPath(thumbnailRoot, _settings.TargetExtension, true); if (File.Exists(thumbPath)) { fileManager.Move(thumbPath, newPath); } } scope.Complete(); var message = string.Format("{0}\t{0}{1}\t{2}", plantPhoto.PhotoId, _settings.TargetExtension, dateString); Logger.Info(message); } } catch (TransactionAbortedException trex) { Logger.Error(string.Format("{0}\t{1}", plantPhoto.PhotoId, trex.Message.Replace(Environment.NewLine, " "))); } catch (Exception exc) { Logger.Error(string.Format("{0}\t{1}", plantPhoto.PhotoId, exc.Message.Replace(Environment.NewLine, " "))); } }
public bool TryFindPlantPhoto(string photoId, out PlantPhoto plantPhoto) { var found = _plantPhotos.FirstOrDefault(p => p.PhotoId == photoId); if (found == null) { plantPhoto = new PlantPhoto { PhotoId = "Not found" }; return(false); } plantPhoto = found; return(true); }
public async Task <IActionResult> AddPlant(AddPlantViewModel model) { var plant = new Plant { Title = model.Name, Description = model.Description, PlantTypeId = model.Type }; var plantId = _db.Plants.Add(plant).Entity.Id; foreach (var photo in Request.Form.Files) { var plantPhoto = new PlantPhoto { PlantId = plantId, PathToPhoto = await _fileKeeper.KeepFileAsync("/images/PlantPhotos/", photo.FileName, photo) }; _db.Photos.Add(plantPhoto); } _db.SaveChanges(); return(RedirectToAction(nameof(AddPlant))); }
public static async Task AddPlantPhotoAsync(PlantPhoto photo) { await asyncDb.InsertAsync(photo); }
public static async Task RemovePlantPhotoAsync(PlantPhoto photo) { await asyncDb.DeleteAsync(photo); }