コード例 #1
0
        public ViewResult Crop(int cropID)
        {
            Crop crop = repository.Crops.Single(p => p.CropId == cropID);
            CustomerViewModel customersViewModel = GetCustomer();

            if (customersViewModel.FirstName != null)
            {
                ViewBag.Customer = GetCustomer();
            }
            CropViewModel cropViewModel = new CropViewModel(crop, true);

            var comments = repository.CropsFeedbacks.Where(d => d.CropId.Equals(cropID)).ToList();

            ViewBag.Comments = comments;

            var ratings = repository.CropsFeedbacks.Where(d => d.CropId.Equals(cropID)).ToList();

            if (ratings.Count() > 0)
            {
                var ratingSum = ratings.Sum(d => d.Rating.Value);
                ViewBag.RatingSum = ratingSum;
                var ratingCount = ratings.Count();
                ViewBag.RatingCount = ratingCount;
            }
            else
            {
                ViewBag.RatingSum   = 0;
                ViewBag.RatingCount = 0;
            }

            return(View(cropViewModel));
        }
コード例 #2
0
        public CropView()
        {
            model = new CropViewModel();

            InitializeComponent();

            this.CropGrid.DataContext = model;
        }
コード例 #3
0
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     base.OnNavigatedTo(e);
     ViewModel = e.Parameter as CropViewModel;
     if (null == ViewModel)
         throw new ArgumentException("Tried to navigate to CropView without sending a ViewModel.");
     ViewModel.SetContentFrame(ContentFrame);
     Bindings.Update();
 }
コード例 #4
0
ファイル: PicSelectorViewModel.cs プロジェクト: ulili5/XamJam
        public PicSelectorViewModel(Page page, PhotoSelectorOptions options)
        {
            this.options  = options;
            CancelCommand = new Command(async() =>
            {
                CropViewModel.PicSelectionResult.UserCancelled = true;
                await Application.Current.MainPage.Navigation.PopModalAsync();
            });
            DoneCommand = new Command(async() =>
            {
                CropViewModel.PicSelectionResult.UserCancelled = false;
                await Application.Current.MainPage.Navigation.PopModalAsync();
            });
            ChangePhotoCommand = new Command(async fake =>
            {
                await CrossMedia.Current.Initialize();

                var canTakePhoto      = CrossMedia.Current.IsTakePhotoSupported;
                var canSelectPhoto    = CrossMedia.Current.IsPickPhotoSupported;
                string selectedOption = null;
                if (canTakePhoto && canSelectPhoto)
                {
                    var buttonText = new[] { options.TakePhotoText, options.SelectPhotoText };
                    selectedOption = await page.DisplayActionSheet(null, CancelText, null, buttonText);
                }
                else if (canTakePhoto)
                {
                    selectedOption = options.TakePhotoText;
                }
                else if (canSelectPhoto)
                {
                    selectedOption = options.SelectPhotoText;
                }
                else
                {
                    //TODO: How to internationalize these strings
                    await page.DisplayAlert("No Photo Support", "This device does not support taking or selecting photos", "Ok");
                    selectedOption = null;
                }

                MediaFile selected = null;
                if (selectedOption == options.TakePhotoText)
                {
                    selected = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions());
                }
                else if (selectedOption == options.SelectPhotoText)
                {
                    selected = await CrossMedia.Current.PickPhotoAsync();
                }
                if (selected != null)
                {
                    var pic = await PicManager.LoadAsync(new Uri(selected.Path));
                    CropViewModel.LoadImage(pic);
                    BugHound.Info($"Setting selected photo to: {selected.Path}");
                }
            });
        }
コード例 #5
0
ファイル: PicSelectorViewModel.cs プロジェクト: ulili5/XamJam
        public async Task InitializeAsync()
        {
            if (options.InitialPhoto != null)
            {
                BugHound.Debug($"Loading initial photo: {options.InitialPhoto}");
                var initialPic = await PicManager.LoadAsync(options.InitialPhoto);

                CropViewModel.LoadImage(initialPic);
                //CropViewModel.PicSelectionResult.Selected = initialPic;
                BugHound.Debug($"Done loading initial photo: {options.InitialPhoto}");
            }
        }
コード例 #6
0
        public CropPage()
        {
            InitializeComponent();

            _viewModel = new CropViewModel(
                ServiceLocator.Current.GetInstance <INavigationFacade>(),
                cropControl,
                ServiceLocator.Current.GetInstance <IDialogService>());

            DataContext = _viewModel;

            Loaded += CropPage_Loaded;
        }
コード例 #7
0
        public async Task UpdateCropAsync(CropViewModel cropViewModel)
        {
            Crop crop = GetCropDetails();

            crop.CropDescription        = cropViewModel.CropDescription;
            crop.CropName               = cropViewModel.CropName;
            crop.IdealClimateLowerRange = cropViewModel.IdealClimateLowerRange;
            crop.IdealClimateUpperRange = cropViewModel.IdealClimateUpperRange;
            crop.IdealSoil              = cropViewModel.IdealSoil;
            crop.MostCommonPest         = cropViewModel.MostCommonPest;
            crop.SoilDescription        = cropViewModel.SoilDescription;
            await DbContext.SaveChangesAsync();
        }
コード例 #8
0
        public async Task <ActionResult> ChangeCropAsync(CropViewModel cropViewModel)
        {
            Crop crop = GetCropDetails();

            if (crop != null)
            {
                await UpdateCropAsync(cropViewModel);
            }
            else
            {
                await AddCropAsync(cropViewModel);
            }
            return(RedirectToAction("Index", "Manage"));
        }
コード例 #9
0
ファイル: LibraryController.cs プロジェクト: QuantumArt/QP
        public JsonResult Crop([FromBody] CropViewModel model)
        {
            var sourcePath = PathInfo.ConvertToPath(model.SourceFileUrl);
            var targetPath = model.OverwriteFile ? sourcePath : PathInfo.ConvertToPath(model.TargetFileUrl);

            if (!PathInfo.CheckSecurity(targetPath).Result)
            {
                return(Json(new { ok = false, message = LibraryStrings.AccessDenied }));
            }

            int sourceWidth = 0, sourceHeight = 0, sourceTop = 0, sourceLeft = 0;

            if (!GetImageSize(sourcePath, ref sourceWidth, ref sourceHeight))
            {
                return(Json(new { ok = false, message = LibraryStrings.ExtensionIsNotAllowed }));
            }

            var targetWidth  = model.Width ?? (int)(sourceWidth * model.Resize);
            var targetHeight = model.Height ?? (int)(sourceHeight * model.Resize);

            sourceWidth  = model.Width.HasValue ? (int)(model.Width.Value / model.Resize) : sourceWidth;
            sourceHeight = model.Height.HasValue ? (int)(model.Height.Value / model.Resize) : sourceHeight;
            sourceTop    = model.Top.HasValue ? (int)(model.Top.Value / model.Resize) : sourceTop;
            sourceLeft   = model.Left.HasValue ? (int)(model.Left.Value / model.Resize) : sourceLeft;

            if (System.IO.File.Exists(sourcePath))
            {
                using (var img = Image.Load(sourcePath))
                {
                    img.Mutate(n => n
                               .Crop(new Rectangle(sourceLeft, sourceTop, sourceWidth, sourceHeight))
                               .Resize(targetWidth, targetHeight)
                               );

                    // ReSharper disable once AssignNullToNotNullAttribute
                    Directory.CreateDirectory(Path.GetDirectoryName(targetPath));
                    if (System.IO.File.Exists(targetPath))
                    {
                        System.IO.File.SetAttributes(targetPath, FileAttributes.Normal);
                        System.IO.File.Delete(targetPath);
                    }
                    img.Save(targetPath);
                }
            }

            return(Json(new { ok = true, message = string.Empty }));
        }
コード例 #10
0
        public async Task AddCropAsync(CropViewModel cropViewModel)
        {
            Farmer farmer = GetFarmerUserDetail();
            Farm   farm   = farmer.Farms;
            Crop   crop   = new Crop();

            crop.CropDescription        = cropViewModel.CropDescription;
            crop.CropName               = cropViewModel.CropName;
            crop.IdealClimateLowerRange = cropViewModel.IdealClimateLowerRange;
            crop.IdealClimateUpperRange = cropViewModel.IdealClimateUpperRange;
            crop.IdealSoil              = cropViewModel.IdealSoil;
            crop.MostCommonPest         = cropViewModel.MostCommonPest;
            crop.SoilDescription        = cropViewModel.SoilDescription;
            crop.Farms = farmer.Farms;
            DbContext.Crops.Add(crop);
            await DbContext.SaveChangesAsync();
        }
コード例 #11
0
        public ViewResult AddCrop()
        {
            CategoriesViewModel   categoriesViewModel = new CategoriesViewModel(repository.Seasons);
            List <SelectListItem> items         = new List <SelectListItem>();
            CropViewModel         cropViewModel = new CropViewModel();

            for (int c = 0; c < categoriesViewModel.Categories.Count; c++)
            {
                items.Add(new SelectListItem {
                    Text    = categoriesViewModel.Categories[c].Name
                    , Value = Convert.ToString(categoriesViewModel.Categories[c].Id)
                });
            }
            //cropViewModel.Categories = categoriesViewModel.Categories;
            ViewBag.Seasons = items;

            return(View());
        }
コード例 #12
0
        public ActionResult AddCrop(CropViewModel cropViewModel)
        {
            Crop crop = GetCropDetails();

            if (crop != null)
            {
                cropViewModel.CropDescription        = crop.CropDescription;
                cropViewModel.CropName               = crop.CropName;
                cropViewModel.IdealClimateLowerRange = crop.IdealClimateLowerRange;
                cropViewModel.IdealClimateUpperRange = crop.IdealClimateUpperRange;
                cropViewModel.IdealSoil              = crop.IdealSoil;
                cropViewModel.MostCommonPest         = crop.MostCommonPest;
                cropViewModel.SoilDescription        = crop.SoilDescription;
                return(View(cropViewModel));
            }
            else
            {
                return(View());
            }
        }
コード例 #13
0
ファイル: LibraryController.cs プロジェクト: QuantumArt/QP
        public JsonResult CheckForCrop([FromBody] CropViewModel model)
        {
            var path = PathInfo.ConvertToPath(model.TargetFileUrl);
            var ext  = Path.GetExtension(path);

            if (System.IO.File.Exists(path))
            {
                return(Json(new { ok = false, message = string.Format(LibraryStrings.FileExistsTryAnother, path) }));
            }

            if (string.IsNullOrEmpty(ext) || string.IsNullOrEmpty(GetMimeType(ext)))
            {
                return(Json(new { ok = false, message = string.Format(LibraryStrings.ExtensionIsNotAllowed, ext) }));
            }

            if (!PathInfo.CheckSecurity(path).Result)
            {
                return(Json(new { ok = false, message = string.Format(LibraryStrings.AccessDenied, path, QPContext.CurrentUserName) }));
            }

            return(Json(new { ok = true, message = string.Empty }));
        }
コード例 #14
0
 public CropPage(CropViewModel viewModel)
 {
     InitializeComponent();
     ViewModel      = viewModel;
     BindingContext = ViewModel;
 }