예제 #1
0
        public ActionResult RemoveLocation(int lockid)
        {
            RecipeLocationViewModel model = (RecipeLocationViewModel)TempData["locationRecipe"];
            var location = model.RecipeLocation.Where(p => p.ID == lockid).FirstOrDefault();

            if (location != null)
            {
                model.NoRecipeLocation.Add(location);
                model.RecipeLocation.Remove(location);
            }
            TempData["locationRecipe"] = model;
            return(PartialView("LocationsEdit", model));
        }
예제 #2
0
        public ActionResult EditLocation(RecipeLocationViewModel model)
        {
            var editModel         = unitOfWork.RecipeRep.Get(model.Id);
            var editModelLocation = editModel.Locations.ToList();

            foreach (var location in editModelLocation)
            {
                editModel.Locations.Remove(location);
            }
            foreach (var location in model.RecipeLocation)
            {
                var loc = unitOfWork.LocationRep.Get(location.ID);
                editModel.Locations.Add(loc);
            }
            unitOfWork.Save();
            return(RedirectToAction("Index"));
        }
예제 #3
0
        public ActionResult RecipeLocations(int id)
        {
            var location = unitOfWork.LocationRep.GetAll().ToList();
            RecipeLocationViewModel model = new RecipeLocationViewModel();

            model.Id             = id;
            model.RecipeLocation = location.Where(r => r.Recipes.Any(re => re.RecipeId == model.Id)).ToList();
            if (model.RecipeLocation == null)
            {
                model.NoRecipeLocation = location;
            }
            else
            {
                model.NoRecipeLocation = location.Where(p => !model.RecipeLocation.Any(r => p.ID == r.ID)).ToList();
            }

            TempData["locationRecipe"] = model;
            return(View("Locations", model));
        }
예제 #4
0
        public HttpResponseMessage UpdateRecipeLocation(RecipeLocationViewModel model)
        {
            var entity = context.Recipe.Find(model.Id);

            if (entity == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }
            entity.Locations.Clear();
            context.SaveChanges();
            foreach (var location in model.Locations)
            {
                var loc = context.Location.Find(location.Id);
                if (loc != null)
                {
                    entity.Locations.Add(loc);
                }
            }
            context.SaveChanges();
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
예제 #5
0
        public HttpResponseMessage GetRecipeLocation(int recipeId)
        {
            var entity = context.Recipe.Find(recipeId);

            if (entity == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }
            var model = new RecipeLocationViewModel();

            model.Id        = entity.RecipeId;
            model.Name      = entity.Name;
            model.Locations = entity.Locations.Select(x => new LocationViewModel()
            {
                Id       = x.ID,
                MarketId = x.MarketId,
                Market   = x.Market.Name,
                Name     = x.Name
            }).ToList();
            return(Request.CreateResponse(HttpStatusCode.OK, model));
        }