public ActionResult AddItem(string id = "", int quantity = 1, string project = "", string redirectUrl = "")
 {
     string resource = Helper.GetResource("Feedback_AddedToShoppingList");
     ShoppingListItem item = new ShoppingListItem();
     Guid result = new Guid();
     Guid.TryParse(id, out result);
     item.ProductTcmID = id;
     item.UserID = base.User.Identity.Name;
     item.Quantity = quantity;
     item.ProjectName = project;
     ShoppingListItem item2 = this.shoppinglistrepository.UpdateAndInsertItem(item);
     if (item == null)
     {
         resource = Helper.GetResource("Feedback_NotAddedToShoppingList");
     }
     if (base.Request.IsAjaxRequest())
     {
         var data = new {
             success = item != null,
             item = (item != null) ? item : null,
             feedback = resource,
             redirect = redirectUrl
         };
         return base.Json(data);
     }
     base.Session.Add("feedback", resource);
     if (!string.IsNullOrEmpty(redirectUrl))
     {
         return this.Redirect(redirectUrl);
     }
     return this.Redirect("/shoppinglist");
 }
 public ShoppingListItem UpdateAndInsertItem(ShoppingListItem item)
 {
     item.AddedDateTime = DateTime.Now;
     IComponent componentInfo = this.GetComponentInfo(item.ProductTcmID);
     item.ProductName = componentInfo.Fields["title"].Value;
     item.Brand = componentInfo.Fields["brand"].Value;
     this.InsertShoppingListItem(item);
     return item;
 }
示例#3
0
        /// <summary>
        /// Adds a new item to the list
        /// </summary>
        /// <param name="newItem">new Item</param>
        /// <returns>updated list</returns>
        public List <ShoppingListItem> addItem(ShoppingListItem newItem)
        {
            var shoppingList = getShoppingList();

            try
            {
                shoppingList.Add(newItem);
                putShoppingList(shoppingList);
            }
            catch (Exception ex)
            {
                // TODO: Handel error
            }

            return(shoppingList);
        }
示例#4
0
        public void post_should_save_to_repository_if_valid_item()
        {
            var request = new ShoppingListItemCreate {
                ItemName = "Item1", Quantity = 1
            };

            var repositoryItem = new ShoppingListItem {
                ItemName = "Item1", Quantity = 1
            };

            _repositoryMock.Setup(x => x.Insert(request)).Returns(repositoryItem);

            var result = _controller.Post(request);

            _repositoryMock.Verify(x => x.Insert(request));
        }
        // GET: ShoppingListItem/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            //ShoppingListItem shoppingListItem = db.ShoppingListItems.Find(id);
            ShoppingListItem shoppingListItem = db.ShoppingListItems.Include(s => s.Files).SingleOrDefault(s => s.ShoppingListItemId == id);

            if (shoppingListItem == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ShoppingListId = new SelectList(db.ShoppingLists, "ShoppingListId", "Name", shoppingListItem.ShoppingListId);
            return(View(shoppingListItem));
        }
示例#6
0
        public void post_should_return_bad_request_if_item_already_exists()
        {
            var request = new ShoppingListItemCreate {
                ItemName = "Item1", Quantity = 1
            };

            var repositoryItem = new ShoppingListItem {
                ItemName = "Item1", Quantity = 1
            };

            _repositoryMock.Setup(x => x.GetItem(request.ItemName)).Returns(repositoryItem);

            var result = _controller.Post(request);

            Assert.AreEqual(result.GetType(), typeof(BadRequestResult));
        }
示例#7
0
        /// <summary>
        /// Updates an item based on index
        /// </summary>
        /// <param name="index">items index</param>
        /// <param name="updatedItem">updated item</param>
        /// <returns>updated list</returns>
        public List <ShoppingListItem> updateItem(Guid id, ShoppingListItem updatedItem)
        {
            var shoppingList = getShoppingList();

            try
            {
                shoppingList.Remove(shoppingList.Where(c => c.id == id).Select(c => c).FirstOrDefault());
                shoppingList.Add(updatedItem);
                putShoppingList(shoppingList);
            }
            catch (Exception ex)
            {
                // TODO: Handel error
            }

            return(shoppingList);
        }
 public static ShoppingListItems FromShoppingListItem(ShoppingListItem item)
 {
     return(new ShoppingListItems
     {
         ItemId = item.Id.HasValue ? item.Id.Value : Guid.NewGuid(),
         Raw = item.Raw,
         Qty = item.Amount == null ? null : (float?)item.Amount.SizeHigh,
         Unit = item.Amount == null ? null : (Units?)item.Amount.Unit,
         Ingredient = item.Ingredient == null ? null : new Ingredients {
             IngredientId = item.Ingredient.Id
         },
         Recipe = item.Recipe == null ? null : new Recipes {
             RecipeId = item.Recipe.Id
         },
         CrossedOut = item.CrossedOut
     });
 }
        public void DeleteItemTest()
        {
            var list = new ShoppingList {
                Name = "test", GroupId = 1
            };
            var item = new ShoppingListItem {
                Name = "testItem", ShoppingListId = list.Id
            };

            list.ShoppingListItems.Add(item);
            DbContext.ShoppingLists.Add(list);
            DbContext.SaveChanges();

            Service.DeleteShoppingListItemAsync(item.Id);

            Assert.DoesNotContain(item, DbContext.ShoppingListItems);
        }
        public IHttpActionResult Post([FromBody] ShoppingListItem item, Guid familyId)
        {
            if (IsDefault(item))
            {
                return(BadRequest());
            }
            //TODO: authenticate whether use has access to family shopping list
            var shopItem = _shopService.GetShoppingListItemDetailsByName(familyId, item.Name);

            if (shopItem != null)
            {
                return(BadRequest("The item is already in the shoppinglist, try updating the existing item."));
            }
            _shopService.AddItemToFamilyShoppingList(familyId, item);
            var returnItem = _shopService.GetShoppingListItemDetailsByName(familyId, item.Name);

            return(Created(WebConfigurationManager.AppSettings["baseUrl"] + $"api/shoppinglists/{familyId}/items/{returnItem.Id}", returnItem));
        }
示例#11
0
        public async Task Create_WhenCalled_ThenResponseIsValid()
        {
            // Arrange
            var item = new ShoppingListItem {
                Label = "Apfel"
            };

            // Act
            var response = await _client.PostAsync("/api/shoppinglistitem", getJsonData(item));

            response.EnsureSuccessStatusCode();

            var responseString = await response.Content.ReadAsStringAsync();

            // Assert
            Assert.Equal("{\"id\":2,\"label\":\"Apfel\",\"isComplete\":false}", responseString);
            Assert.Equal("/api/ShoppingListItem/2", response.Headers.Location.LocalPath);
        }
示例#12
0
        public Task UpdateShoppingListItemAsync(ShoppingListItem listItem)
        {
            var updatedListItem = _context.ShoppingListItems.Find(listItem.Id)
                                  ?? throw new EntityNotFoundException("Cannot find shopping list item with ID: {listItem.Id}");

            if (!string.IsNullOrWhiteSpace(listItem.Name))
            {
                updatedListItem.Name = listItem.Name;
            }

            if (listItem.IsTicked != null)
            {
                updatedListItem.IsTicked = listItem.IsTicked;
            }

            _context.ShoppingListItems.Update(updatedListItem);
            return(_context.SaveChangesAsync());
        }
示例#13
0
            public void TestBlankLAList()
            {
                ShoppingList testList3 = new ShoppingList()
                {
                    Name = "Test List 3"
                };
                ShoppingListItem testInsertItem = new ShoppingListItem()
                {
                    Description = "Test Insert", Checked = false
                };

                Assert.IsNotNull(testInsertItem, "Test insert item is null.");

                testList3.ShoppingListItems.Add(testInsertItem);
                Assert.AreEqual <int>(1, testList3.ShoppingListItems.Count, "List item not added.");
                testList3.ShoppingListItems.Remove(testInsertItem);
                Assert.AreEqual <int>(0, testList3.ShoppingListItems.Count, "List item not removed.");
            }
        public void UpdateItemTest()
        {
            var list = new ShoppingList {
                Name = "test", GroupId = 1
            };
            var item = new ShoppingListItem {
                Name = "testItem", ShoppingListId = list.Id
            };

            list.ShoppingListItems.Add(item);
            DbContext.ShoppingLists.Add(list);
            DbContext.SaveChanges();

            item.Name = "testItem2";
            Service.UpdateShoppingListItemAsync(item).Wait();

            Assert.True(DbContext.ShoppingListItems.Any(i => i.Name == "testItem2"));
        }
示例#15
0
        /* int pageSize = 3;
         * int pageNumber = (page ?? 1);
         * //var shoppingListItems = db.ShoppingListItems.Include(s => s.ShoppingList);
         * return View(shopinglists.ToPagedList(pageNumber, pageSize));
         * }*/

        // GET: ShoppingListModel/Details/5
        public ActionResult Details(int?id)
        {
            //replace with shoppinglistitem index
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ShoppingListItem shoppingListItem = db.ShoppingListItems.Include(s => s.Files).SingleOrDefault(s => s.ShoppingListItemId == id);

            Data.ShoppingList shoppingListModel = db.ShoppingLists.Find(id);
            if (shoppingListModel == null)
            {
                return(HttpNotFound());
            }

            //var i = new ShoppingListItem {ShoppingListId = id.Value};
            return(View(shoppingListModel));
        }
示例#16
0
        public void get_shopping_list_item_should_return_ok_with_shopping_item_data_when_valid()
        {
            var itemName = "Item1";

            var shoppingListItem = new ShoppingListItem {
                ItemName = "Item1", Quantity = 1
            };

            _repositoryMock.Setup(x => x.GetItem(itemName)).Returns(shoppingListItem);

            var result = _controller.GetItem(itemName);

            Assert.AreEqual(result.GetType(), typeof(OkNegotiatedContentResult <ShoppingListItem>));
            var actualShoppingListItem = ((OkNegotiatedContentResult <ShoppingListItem>)result).Content;

            Assert.AreEqual(actualShoppingListItem.ItemName, "Item1");
            Assert.AreEqual(actualShoppingListItem.Quantity, 1);
        }
        public ActionResult Edit(ComboViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var userId = User.Identity.GetUserId();
                var list   = _context.ShoppingLists.FirstOrDefault(s => s.Id == vm.ShoppingListViewModel.Id);

                if (list == null)
                {
                    Response.StatusCode = 404;
                    ViewBag.Message     = "Ostoslistaa ei löytynyt";
                    return(View("Error"));
                }

                if (list.OwnerId != userId && !EditAllowedForCurrentUser(list))
                {
                    Response.StatusCode = 403;
                    ViewBag.Message     = "Ei oikeutta käsitellä ostoslistaa";
                    return(View("Error"));
                }

                var item = new ShoppingListItem
                {
                    Name           = vm.ShoppingListItemViewModel.Name,
                    Quantity       = vm.ShoppingListItemViewModel.Quantity,
                    Added          = DateTime.UtcNow,
                    ShoppingListId = vm.ShoppingListViewModel.Id
                };

                _context.ShoppingListItems.Add(item);
                _context.SaveChanges();

                return(RedirectToAction("Edit", "ShoppingLists", new { id = vm.ShoppingListViewModel.Id }));
            }

            var shoppingList = _context.ShoppingLists.Include(sl => sl.Items).SingleOrDefault(sl => sl.Id == vm.ShoppingListViewModel.Id);

            var comboVm = new ComboViewModel
            {
                ShoppingListViewModel = ShoppingListViewModel.Create(shoppingList)
            };

            return(View(comboVm));
        }
    public void Setup(ShoppingListItem shoppingList)
    {
        ownerText.text = shoppingList.owner;

        foreach (string item in shoppingList.list)
        {
            GameObject newText = (GameObject)Instantiate(textObject);

            Text theText = newText.transform.GetComponent <Text>();

            theText.text = item;

            newText.transform.SetParent(listText);
        }

        totalCostText.text = shoppingList.totalCost.ToString() + "kr";

        transform.localScale = new Vector3(1, 1, 1); // Forc to dont scale
    }
示例#19
0
        public async Task CreateOrMergeItemAsync(ShoppingListItem item)
        {
            ShoppingListItem itemOnList = await GetItemByNameAsync(item.OwnerId, item.Name);

            // check if items could be merged
            if (itemOnList != null && (ValueUnit.TryParse(itemOnList.Quantity, out ValueUnit onlistValue) && ValueUnit.TryParse(item.Quantity, out ValueUnit coreDataValue)))
            {
                // merge items
                ValueUnit newValueUnit = ValueUnit.Add(onlistValue, coreDataValue);

                itemOnList.Quantity = newValueUnit.ToString();
            }
            else
            {
                // create new item
                _context.ShoppingListItems.Add(item);
            }
            await _context.SaveChangesAsync();
        }
示例#20
0
            public void TestAddDuplicateItem()
            {
                var newItem = new ShoppingListItem()
                {
                    ListId      = 3,
                    Description = "Test Insert 1",
                    Checked     = false
                };

                var result = listQueries.AddItemToList(newItem);

                Assert.AreEqual(true, result);
                Assert.IsNotNull(db.LAListItems.Where(e => e.Description.Equals("Test Insert 1")).FirstOrDefault());
                Assert.AreEqual(2, db.LALists.Find(3).LAListItems.Count);

                var item = db.LAListItems.Where(e => e.Description.Equals("Test Insert 1")).FirstOrDefault();

                Assert.IsNotNull(item);
            }
示例#21
0
        //TODO: convert all this stuff and get the image from spoonacular
        private async Task <ShoppingListItem> ConvertToShoppingListItem(ItemShoppingListLinkEntity itemShoppingListLink, int storeId, CancellationToken ct)
        {
            /*
             *     public class ShoppingListItem
             *     {
             *      public int Id { get; set; }
             *
             *      public string Image { get; set; }
             *
             *      public string Name { get; set; }
             *
             *      public decimal Price { get; set; }
             *
             *      public bool InStock { get; set; }
             *
             *      public int StockAmount { get; set; }
             *
             *      public string Aisle { get; set; }
             *
             *      public string Section { get; set; }
             *
             *      public int QuantityBought { get; set; }
             *     }
             *
             */

            ItemEntity itemEntity = await _itemRepository.GetEntityAsync(itemShoppingListLink.ItemId, ct);

            ItemStoreLinkEntity itemStoreLink = await _itemStoreLinkRepository.GetEntityAsync(itemEntity.Id, storeId, ct);

            ShoppingListItem shoppingListItem = new ShoppingListItem
            {
                LinkId       = itemShoppingListLink.Id,
                Name         = itemEntity.Name,
                Price        = itemStoreLink.Price,
                InStock      = itemStoreLink.InStock,
                StockAmount  = itemStoreLink.StockAmount,
                ItemQuantity = itemShoppingListLink.ItemQuantity
            };

            return(shoppingListItem);
        }
        public async Task <IActionResult> AddShoppingListItem([FromBody] ShoppingListItemToAddDto shoppingLitItemToAddDto)
        {
            if (shoppingLitItemToAddDto != null)
            {
                IngredientDto newIngredientDto = await _ingredientRepo.GetIngredientsFromAPI(shoppingLitItemToAddDto.SpoonacularId);

                string           image            = newIngredientDto.image;
                ShoppingListItem shoppingListItem = _mapper.Map <ShoppingListItem>(shoppingLitItemToAddDto);
                shoppingListItem.IsOnShoppingList = true;
                var userId = User.FindFirst(claim => claim.Type == ClaimTypes.NameIdentifier).Value;
                shoppingListItem.CreatedBy = int.Parse(userId);
                shoppingListItem.Image     = image;
                _repo.Add <ShoppingListItem>(shoppingListItem);
                _repo.SaveAll();

                return(StatusCode(201));
            }
            Response.StatusCode = 400;
            return(Content("Naughty"));
        }
        public void UpdateShoppingListItem_ReturnUpdatedShoppingListItem()
        {
            var random           = new Random();
            var shoppingListItem = new ShoppingListItem {
                Name = Guid.NewGuid().ToString(), Quantity = (uint)random.Next(int.MaxValue)
            };
            var updatedItem = new UpdateShoppingListItem()
            {
                Quantity = (uint)random.Next(int.MaxValue)
            };

            CheckoutClient.OfficeShoppingService.AddShoppingListItem(testGuid, shoppingListItem);

            var response = CheckoutClient.OfficeShoppingService.UpdateShoppingListItem(testGuid, shoppingListItem.Name, updatedItem);

            response.Should().NotBeNull();
            response.HttpStatusCode.Should().Be(HttpStatusCode.OK);
            response.Model.Name.Should().Be(shoppingListItem.Name);
            response.Model.Quantity.Should().Be(updatedItem.Quantity);
        }
示例#24
0
        public async Task <IActionResult> GetHomeStoreShoppingLists(CancellationToken ct)
        {
            var currentUser  = HttpContext.User;
            var userclaim    = currentUser.Claims.First();
            var userId       = Guid.Parse(userclaim.Value);
            var shoppingUser = await _shoppingUserRepository.GetEntityAsync(userId, ct);

            if (shoppingUser == null)
            {
                return(BadRequest(new { error = "Not allowed to access shopping lists" }));
            }

            var lists = await _shoppingListRepository.GetAllShoppingListsForUserForACertainStore(shoppingUser.Id, shoppingUser.HomeStoreId, ct);

            List <ShoppingList> usersShoppingLists = new List <ShoppingList>();

            foreach (var list in lists)
            {
                ShoppingList sl = new ShoppingList();
                sl.Id             = list.Id;
                sl.Name           = list.Name;
                sl.TimeOfCreation = list.TimeOfCreation;

                var itemListLinks = await _itemListLinkRepository.GetAllByShoppingListId(list.Id, ct);

                //TODO: Look up item in shoppinglist item link repository
                foreach (var itemlistlink in itemListLinks)
                {
                    ShoppingListItem item = await GetFullItemInfo(itemlistlink, list.StoreId, ct);

                    sl.Items.Add(item);
                }

                sl.TotalCost  = sl.Items.Select(i => i.Price * i.ItemQuantity).ToList().Sum();
                sl.TotalItems = sl.Items.Select(i => i.ItemQuantity).ToList().Sum();

                usersShoppingLists.Add(sl);
            }

            return(Ok(usersShoppingLists));
        }
示例#25
0
        public async Task <IActionResult> GetUsersShoppingItem(int linkId, CancellationToken ct)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var currentUser  = HttpContext.User;
            var userclaim    = currentUser.Claims.First();
            var userId       = Guid.Parse(userclaim.Value);
            var shoppingUser = await _shoppingUserRepository.GetEntityAsync(userId, ct);

            if (shoppingUser == null)
            {
                return(BadRequest("You are not a shopping user"));
            }

            var link = await _itemListLinkRepository.GetShoppingItem(linkId, ct);

            if (link == null)
            {
                return(NotFound("Item Shopping List Link Not Found"));
            }

            var item = await _itemRepository.GetEntityAsync(link.ItemId, ct);

            var itemStoreLink = await _itemStoreLinkRepository.GetEntityAsync(link.ItemId, shoppingUser.HomeStoreId, ct);

            var shoppingItem = new ShoppingListItem
            {
                LinkId       = link.Id,
                Image        = null,
                Name         = item.Name,
                Price        = itemStoreLink.Price,
                InStock      = itemStoreLink.InStock,
                StockAmount  = itemStoreLink.StockAmount,
                ItemQuantity = link.ItemQuantity
            };

            return(Ok(shoppingItem));
        }
        public IActionResult Update(long id, [FromBody] ShoppingListItem item)
        {
            if (item == null || item.Id != id)
            {
                return(BadRequest());
            }

            var dbItem = _context.ShoppingListItems.FirstOrDefault(t => t.Id == id);

            if (dbItem == null)
            {
                return(NotFound());
            }

            dbItem.IsComplete = item.IsComplete;
            // dbItem.Label = item.Label; not yet possible

            _context.ShoppingListItems.Update(dbItem);
            _context.SaveChanges();
            return(new ObjectResult(item));
        }
示例#27
0
        public void should_post_shopping_list_item_and_return_created_with_correct_content()
        {
            var request = new ShoppingListItemCreate {
                ItemName = "Item1", Quantity = 1
            };

            var repositoryItem = new ShoppingListItem {
                ItemName = "Item1", Quantity = 1
            };

            _repositoryMock.Setup(x => x.Insert(request)).Returns(repositoryItem);

            var result = _controller.Post(request);

            Assert.AreEqual(result.GetType(), typeof(CreatedNegotiatedContentResult <ShoppingListItem>));
            var createdResult = (CreatedNegotiatedContentResult <ShoppingListItem>)result;

            Assert.AreEqual(createdResult.Location, $"api/shoppinglist/?itemname={request.ItemName}");
            Assert.AreEqual(createdResult.Content.ItemName, request.ItemName);
            Assert.AreEqual(createdResult.Content.Quantity, request.Quantity);
        }
        public OperationResult Post(int id)
        {
            ShoppingListItem item = _shoppingListService.GetItem(id);

            //diff.Apply(item);
            if (item.NewImage.Length > 0)
            {
                using (Stream newImageStream = item.NewImage.OpenStream())
                {
                    // I am basically crap at this...
                    string path   = HttpContext.Current.Server.MapPath("~/images/") + item.NewImage.FileName;
                    var    buffer = new byte[newImageStream.Length];
                    newImageStream.Read(buffer, 0, buffer.Length);
                    File.WriteAllBytes(path, buffer);
                }
                item.Image = new ShoppingListItemImage(item.NewImage.FileName, item);
            }
            return(new OperationResult.SeeOther {
                RedirectLocation = item.CreateUri()
            });
        }
示例#29
0
        public async Task <IActionResult> PostItem(int shoppingListId, [FromBody] ShoppingListItem item)
        {
            var list = await db.ShoppingLists.Include(l => l.Items).SingleOrDefaultAsync(l => l.Id == shoppingListId);

            if (list == null)
            {
                return(NotFound());
            }

            if (list.Items == null)
            {
                list.Items = new List <ShoppingListItem>();
            }

            list.Items.Add(item);
            await db.SaveChangesAsync();

            await notifications.NotifyShoppingListItemAdded(shoppingListId, item);

            return(CreatedAtRoute("ShoppingListItem", new { shoppingListId, item.Id }, item));
        }
        public void CreateItemTest()
        {
            var list = new ShoppingList {
                Name = "test", GroupId = 1
            };

            DbContext.ShoppingLists.Add(list);
            DbContext.SaveChanges();

            var item = new ShoppingListItem {
                Name = "testItem", ShoppingListId = list.Id
            };

            Service.CreateShoppingListItemAsync(item).Wait();

            Assert.Contains(item, DbContext.ShoppingListItems);

            var result = DbContext.ShoppingLists.Find(list.Id);

            Assert.Contains(item, result.ShoppingListItems);
        }
        public ActionResult ShoppingList(String name)
        {
            dynamic result;

            if (_context.shoppinglistitems.Find(name) == null)
            {
                var newitem = new ShoppingListItem()
                {
                    name = name
                };
                _context.Add(newitem);
                _context.SaveChanges();
                result = RedirectToAction("ShoppingList");
            }
            else
            {
                result = Content("ERROR: This item already exists!");
            }

            return(result);
        }
示例#32
0
    void Start()
    {
        if (autoPopulateShoppingList)
        {
            shoppingListItems = new List <ShoppingListItem>();

            foreach (Item item in FindObjectsOfType <Item>())
            {
                bool needToAdd = true;

                foreach (ShoppingListItem itemInList in shoppingListItems)
                {
                    if (item.itemName.Equals(itemInList.ItemName))
                    {
                        itemInList.ItemAmount++;
                        needToAdd = false;
                    }
                }

                if (needToAdd)
                {
                    ShoppingListItem tempItem = new ShoppingListItem();
                    tempItem.ItemName = item.itemName;
                    tempItem.ItemAmount++;
                    shoppingListItems.Add(tempItem);
                }
            }
        }

        items = new GameObject[shoppingListItems.Count];
        for (int i = 0; i < items.GetLength(0); i++)
        {
            ShoppingListItem x    = shoppingListItems[i];
            GameObject       item = Instantiate(itemPrefab, Vector3.zero, new Quaternion(0, 0, 0, 0));
            item.transform.SetParent(verticalLayoutGroup.transform);
            item.GetComponent <Toggle>().isOn         = false;
            item.GetComponentInChildren <Text>().text = x.ItemName + "(" + x.currentAmount + "/" + x.ItemAmount + ")";
            items[i] = item;
        }
    }
示例#33
0
 public override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     HttpContextBase httpContext = filterContext.RequestContext.HttpContext;
     NameValueCollection @params = httpContext.Request.Params;
     if (httpContext.User.Identity.IsAuthenticated && !string.IsNullOrEmpty(@params["action"]))
     {
         if (@params["action"] == "addtoscrapbook")
         {
             ScrapbookItem item = new ScrapbookItem {
                 UserID = httpContext.User.Identity.Name,
                 ImageURL = @params["imageURL"],
                 ItemDescription = @params["description"],
                 ItemType = @params["type"],
                 SourceURL = @params["sourceUrl"],
                 SourceDescription = @params["sourceDescription"]
             };
             ScrapbookGateway gateway = new ScrapbookGateway();
             if ((gateway.InsertScrapbookItem(item) != null) && !string.IsNullOrEmpty(@params["ReturnUrl"]))
             {
                 filterContext.HttpContext.Session.Add("feedback", Helper.GetResource("Feedback_AddedToScrapbook"));
                 filterContext.Result = new RedirectResult(@params["ReturnUrl"]);
             }
             base.OnActionExecuting(filterContext);
         }
         if (@params["action"] == "addtoshoppinglist")
         {
             string str = (@params["project"] != null) ? @params["project"] : string.Empty;
             int result = 0;
             bool flag = int.TryParse(@params["quantity"], out result);
             IComponent componentInfo = this.GetComponentInfo(@params["tcm-id"]);
             ShoppingListItem item4 = new ShoppingListItem {
                 AddedDateTime = DateTime.Now,
                 Brand = componentInfo.Fields["brand"].Value,
                 ProductTcmID = @params["tcm-id"],
                 ProductName = componentInfo.Fields["title"].Value,
                 ProjectName = str,
                 Quantity = result,
                 UserID = httpContext.User.Identity.Name
             };
             ShoppingListGateway gateway2 = new ShoppingListGateway();
             if ((gateway2.InsertShoppingListItem(item4) != null) && !string.IsNullOrEmpty(@params["ReturnUrl"]))
             {
                 filterContext.HttpContext.Session.Add("feedback", Helper.GetResource("Feedback_AddedToShoppingList"));
                 filterContext.Result = new RedirectResult(@params["ReturnUrl"]);
             }
             base.OnActionExecuting(filterContext);
         }
         if (@params["action"] == "ReturnUrl")
         {
             if (!string.IsNullOrEmpty(@params["ReturnUrl"]))
             {
                 filterContext.Result = new RedirectResult(@params["ReturnUrl"]);
             }
             base.OnActionExecuting(filterContext);
         }
         if (@params["action"] == "download")
         {
             if (!string.IsNullOrEmpty(@params["itemLink"]))
             {
                 filterContext.Result = new RedirectResult(@params["ReturnUrl"] + "?download=" + @params["itemLink"]);
             }
             base.OnActionExecuting(filterContext);
         }
     }
 }
 public ShoppingListItem InsertShoppingListItem(ShoppingListItem item)
 {
     return this.gw.InsertShoppingListItem(item);
 }
        public void UpdateItem(int weekNumber, ShoppingListItem input)
        {
            var shoppingList = _db.Single<ShoppingList>(q => q.WeekNumber == weekNumber);
            var item = shoppingList.Items.Single(i => i.Id == input.Id);

            if (item.Buy != input.Buy)
            {
                foreach (var i in shoppingList.Items.Where(r => r.Product == item.Product))
                {
                    i.Buy = input.Buy;
                }
            }

            item.PopulateWith(input);
            _db.Update(shoppingList);
        }