public ActionResult Create(CreatePizzaViewModel pizzaResponse, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    string pic  = Path.GetFileName(file.FileName);
                    string path = Path.Combine(
                        Server.MapPath("~/Content/Images"), pic);
                    // file is uploaded
                    file.SaveAs(path);

                    // save the image path path to the database or you can send image
                    // directly to database
                    // in-case if you want to store byte[] ie. for DB
                    using (MemoryStream ms = new MemoryStream())
                    {
                        file.InputStream.CopyTo(ms);
                        byte[] array = ms.GetBuffer();
                    }

                    pizzaResponse.ImgUrl = "/Content/Images/" + pic;
                }
                else
                {
                    pizzaResponse.ImgUrl = "/Content/Images/CustomPizza.png";
                }

                repository.CreatePizzaForUser(pizzaResponse, User.Identity.GetUserId());
                if (User.IsInRole(UserRoles.User))
                {
                    ViewBag.Title = "These are your custom pizzas";
                    return(RedirectToAction("MyPizzas"));
                }
                ViewBag.Title = "Barka 5's Menu";
                return(RedirectToAction("Index"));
            }

            foreach (var TypeOfIngredient in Enum.GetValues(typeof(IngredientType)))
            {
                pizzaResponse.TypeIngredientListPairs.Add(TypeOfIngredient.ToString(), repository.GetIngredientsByType((IngredientType)TypeOfIngredient));
            }
            return(View(pizzaResponse));
        }
        private CreatePizzaViewModel setupCreateOrEditViewModel(Guid?id)
        {
            CreatePizzaViewModel viewModel = new CreatePizzaViewModel();

            if (id != null)
            {
                var a = id;

                var pizzaToEdit = repository.GetPizza(id);

                viewModel.PizzaId = id;

                foreach (var TypeOfIngredient in Enum.GetValues(typeof(IngredientType)))
                {
                    viewModel.TypeIngredientListPairs.Add(TypeOfIngredient.ToString(), repository.GetIngredientsByType((IngredientType)TypeOfIngredient));
                }

                viewModel.selectedIngredients = repository.GetIngredientsForPizza(id)
                                                .Select(x => x.IngredientId.ToString())
                                                .ToList();

                viewModel.Name       = pizzaToEdit.Name;
                viewModel.IncomeCoef = pizzaToEdit.incomeCoeficient;
                viewModel.Size       = pizzaToEdit.Size;
                viewModel.ImgUrl     = pizzaToEdit.ImgUrl;
            }
            else
            {
                foreach (var TypeOfIngredient in Enum.GetValues(typeof(IngredientType)))
                {
                    viewModel.TypeIngredientListPairs.Add(TypeOfIngredient.ToString(), repository.GetIngredientsByType((IngredientType)TypeOfIngredient));
                }
            }

            return(viewModel);
        }