コード例 #1
0
        private void btnUpdate_Click(object sender, RoutedEventArgs e)
        {
            if (lines.Count == 0)
            {
                MessageBox.Show("Remember to add Ingredients");
                return;
            }
            if (string.IsNullOrEmpty(txtTitle.Text) || string.IsNullOrEmpty(txtInstructions.Text))
            {
                MessageBox.Show("Title and Instruction might not be empty");
            }

            var recipeDTO = new
            {
                Id              = recipe.Id,
                Title           = txtTitle.Text,
                Instruction     = txtInstructions.Text,
                IngredientLines = new List <object>(),
                Images          = new List <object>(),
                User            = new { Id = recipe.User.Id },
                RowVer          = this.RowVersion
            };

            foreach (IngredientLineModel line in lines)
            {
                if (!string.IsNullOrEmpty(line.Ingredient.Name) && line.Amount > 0)
                {
                    var IngredientLineDTO = new {
                        Ingredient  = new { Name = line.Ingredient.Name },
                        Amount      = line.Amount,
                        MeasureUnit = line.MeasureUnitInt
                    };
                    recipeDTO.IngredientLines.Add(IngredientLineDTO);
                }
            }

            foreach (ImageModel image in images)
            {
                if (!string.IsNullOrEmpty(image.FileName))
                {
                    recipeDTO.Images.Add(new { FileName = image.FileName });
                }
            }

            RFApiResult result = rc.UpdateRecipe(recipeDTO);

            if (result.StatusCode == System.Net.HttpStatusCode.OK)
            {
                RecipeModel updatedRecipeModel = rc.FindByCondition("id", recipeDTO.Id);

                this.RowVersion = updatedRecipeModel.rowVer;
            }

            MessageBox.Show(result.Message);
        }
コード例 #2
0
        public ActionResult SubmitCreate(RecipeModel rm)
        {
            RecipeCaller rc = new RecipeCaller(ConfigurationManager.AppSettings["RecipeFinderApiBaseUrl"]);

            RecipeDTO recipeToBeCreated = new RecipeDTO();

            recipeToBeCreated.Title = rm.Title;
            recipeToBeCreated.User  = new UserDTO()
            {
                Id = 1
            };
            recipeToBeCreated.Instruction     = rm.Instruction;
            recipeToBeCreated.IngredientLines = new List <IngredientLineDTO>();
            recipeToBeCreated.Images          = new List <ImageDTO>();

            if (rm.IngredientLines != null)
            {
                foreach (var item in rm.IngredientLines)
                {
                    IngredientLineDTO lineDTO = new IngredientLineDTO();
                    lineDTO.Ingredient = new IngredientDTO()
                    {
                        Name = item.Ingredient.Name
                    };
                    lineDTO.Amount          = item.Amount;
                    lineDTO.MeasureUnitText = item.MeasureUnit;

                    recipeToBeCreated.IngredientLines.Add(lineDTO);
                }
            }
            if (rm.Images != null)
            {
                foreach (var item in rm.Images)
                {
                    ImageDTO image = new ImageDTO();
                    image.FileName = item.FileName;

                    recipeToBeCreated.Images.Add(image);
                }
            }

            RFApiResult response = rc.CreateRecipe(recipeToBeCreated);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                SetFlash(FlashMessageType.Success, response.Message);
            }
            else
            {
                SetFlash(FlashMessageType.Danger, response.Message);
            }

            return(Redirect(Url.Action("Index", "Home")));
        }
コード例 #3
0
        public ActionResult SubmitCreate(CreateUserViewModel vm)
        {
            UserCaller  uc       = new UserCaller(ConfigurationManager.AppSettings["RecipeFinderApiBaseUrl"]);
            RFApiResult response = uc.CreateUser(new User()
            {
                Username = vm.Username, Email = vm.Email, Password = vm.Password
            });

            if (response.Success)
            {
                SetFlash(Models.FlashMessageType.Success, response.Message);
            }
            else
            {
                SetFlash(Models.FlashMessageType.Danger, response.Message);
            }

            return(Redirect(Url.Action("Create", "User")));
        }