Exemplo n.º 1
0
        public IActionResult PutRecipe(EditRecipe model)
        {
            var recipe = mapper.Map(model);

            service.UpdateRecipe(recipe);
            return(RedirectToAction(nameof(GetRecipe), new { id = model.Id }));
        }
Exemplo n.º 2
0
        public Recipe Map(EditRecipe model)
        {
            var recipe = new Recipe
            {
                Id                 = model.Id,
                Description        = model.Description,
                Title              = model.Title,
                SourceURL          = model.SourceURL,
                CookingTimeMinutes = model.CookingTimeMinutes,
                CookingTypeId      = model.CookingTypeId,
                DishTypeId         = model.DishTypeId,
                RecipeTypeId       = model.RecipeTypeId,
                Stages             = model.Stages?.Select(s => stageMapper.Map(s)).ToList(),
                Ingredients        = model.Ingredients?.Select(i => ingredientMapper.Map(i)).ToList()
            };

            if (model.Thumbnail != null)
            {
                recipe.Thumbnail = GetThumbnail(model.Thumbnail);
            }
            else if (model.ExistingImage != null)
            {
                recipe.Thumbnail = new File
                {
                    Content   = Convert.FromBase64String(model.ExistingImage.Base64),
                    Extension = model.ExistingImage.Extension
                };
            }

            return(recipe);
        }
Exemplo n.º 3
0
        public EditRecipe MapToEdit(Recipe model)
        {
            var editRecipe = new EditRecipe
            {
                Id                 = model.Id,
                Description        = model.Description,
                Title              = model.Title,
                SourceURL          = model.SourceURL,
                CookingTimeMinutes = model.CookingTimeMinutes,
                CookingTypeId      = model.CookingTypeId,
                DishTypeId         = model.DishTypeId,
                RecipeTypeId       = model.RecipeTypeId,
                Stages             = model.Stages?.Select(s => stageMapper.MapToEdit(s)).ToList(),
                Ingredients        = model.Ingredients?.Select(i => ingredientMapper.Map(i)).ToList()
            };

            if (model.Thumbnail != null)
            {
                editRecipe.ExistingImage = new ImageViewModel
                {
                    Base64    = Convert.ToBase64String(model.Thumbnail.Content),
                    Extension = model.Thumbnail.Extension
                };
            }

            return(editRecipe);
        }
 public EditRecipeViewModel(EditRecipe editView, tblUser user, tblRecipe recipeToEdit)
 {
     this.editView   = editView;
     recipe          = recipeToEdit;
     author          = user;
     recipe.authorId = recipeToEdit.authorId;
 }
Exemplo n.º 5
0
        public App()
        {
            InitializeComponent();

            AboutPage      = new AboutPage();
            AddRecipe      = new AddRecipe();
            ItemDetailPage = new ItemDetailPage();
            NewItemPage    = new NewItemPage();
            Recipes        = new Recipes();
            TakePhoto      = new TakePhoto();
            EditRecipe     = new EditRecipe();

            NaviService = _container.Resolve <INavigationService>() as NavigationService;

            var pageFactory = _container.Resolve <IPageFactory>();
            var home        = pageFactory.GetPage(Pages.MainPage) as TabbedPage;

            StartupPage = home;
            MainPage    = StartupPage;
        }
Exemplo n.º 6
0
 private void InitializeAllComponents()
 {
     TablesController       = new System.Windows.Forms.TabControl();
     recipesTable           = new System.Windows.Forms.TabPage();
     createNewRecipeButton  = new System.Windows.Forms.Button();
     TextBoxForSearchRecipe = new System.Windows.Forms.TextBox();
     recipeSearch           = new System.Windows.Forms.Label();
     recipeGrid             = new System.Windows.Forms.DataGridView();
     recipeNameColumn       = new System.Windows.Forms.DataGridViewTextBoxColumn();
     deleteRecipeColumn     = new System.Windows.Forms.DataGridViewButtonColumn();
     recipeIdColumn         = new System.Windows.Forms.DataGridViewTextBoxColumn();
     recipeEditor           = new RecipeBook.Gui.EditRecipe();
     TableOfItems           = new System.Windows.Forms.TabPage();
     itemEditor             = new RecipeBook.Gui.ItemEditor();
     createNewItem          = new System.Windows.Forms.Button();
     TextBoxForSearchItem   = new System.Windows.Forms.TextBox();
     IngredientSearch       = new System.Windows.Forms.Label();
     IngredientTableCreator = new System.Windows.Forms.DataGridView();
     IngredientNameColumn   = new System.Windows.Forms.DataGridViewTextBoxColumn();
     IngredientDeleteColumn = new System.Windows.Forms.DataGridViewButtonColumn();
     IngredientIdColumn     = new System.Windows.Forms.DataGridViewTextBoxColumn();
 }
 private void EditExecute()
 {
     try
     {
         if (recipe != null)
         {
             //author can edit only his recipes
             if (currentUser.role == "user")
             {
                 if (currentUser.userId == recipe.authorId)
                 {
                     EditRecipe editRecipe = new EditRecipe(currentUser, recipe);
                     editRecipe.ShowDialog();
                 }
                 else
                 {
                     MessageBox.Show("Only author or admin can edit this Recipe");
                 }
             }
             //admin can edit all recipes
             else
             {
                 EditRecipe editRecipe = new EditRecipe(currentUser, recipe);
                 editRecipe.ShowDialog();
             }
         }
         else
         {
             MessageBox.Show("Please select the recipe that you want to edit.");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }