Ejemplo n.º 1
0
        public async Task <ActionResult <GroceryList> > PutGroceryList(Guid id, GroceryList groceryList)
        {
            if (id != groceryList.Id)
            {
                return(BadRequest());
            }
            _context.Entry(groceryList).State = EntityState.Modified;


            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_context.GroceryLists.Any(e => e.Id == id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(groceryList));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <GroceryList> > PostGroceryList(GroceryList groceryList)
        {
            _context.GroceryLists.Add(groceryList);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetGroceryList", new { id = groceryList.Id }, groceryList));
        }
        public void deleteGroceryList(int id)
        {
            GroceryList gdb = _groceryContext.GroceryLists.Where(p => p.GroceryListId == id).FirstOrDefault();

            _groceryContext.GroceryLists.Remove(gdb);
            _groceryContext.SaveChanges();
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Edit(int id, [Bind("GroceryListId,ShopperId,ListName,Budget,RealTotalCost,StoreName,ParkingSpot,Date,City,State,ZipCode")] GroceryList groceryList)
        {
            if (id != groceryList.GroceryListId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(groceryList);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GroceryListExists(groceryList.GroceryListId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(groceryList));
        }
Ejemplo n.º 5
0
        public async Task <ActionResult <GroceryList> > PostGroceryList(GroceryList groceryList)
        {
            User user = await _context.Users.FindAsync(groceryList.UserId);

            House house = await _context.Houses.FindAsync(groceryList.HouseId);


            groceryList = new GroceryList
            {
                Label       = groceryList.Label,
                CreatedAt   = groceryList.CreatedAt,
                EditedAt    = groceryList.EditedAt,
                HouseId     = groceryList.HouseId,
                House       = house,
                ListCreator = user,
                UserId      = user.UID,
                Privilige   = groceryList.Privilige,
                IsStarred   = groceryList.IsStarred,
                Items       = new List <Item>()
            };



            _context.GroceryLists.Add(groceryList);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetGroceryList", new { id = groceryList.Id }, groceryList));
        }
Ejemplo n.º 6
0
        public IResponse UpdateGroceryList(GroceryListViewModel groceryList)
        {
            // Convertion for groceryList view model object to a POCO groceryList object
            GroceryList groceryListUpdated = new GroceryList
            {
                GroceryListID = groceryList.GroceryListId,
                Products      = groceryList.Products.Select(x => new ProductGroceryList
                {
                    ProductID = x.ProductId,
                    Tagged    = x.Tagged,
                }).ToList()
            };

            try
            {
                this.GroceryRepository.UpdateGroceryList(groceryListUpdated);
                this.GroceryRepository.Save();
                return(new Response("0", "Success"));
            }
            catch (Exception ex)
            {
                //Logging exception and return an error response
            }

            return(new Response("1", "Error updating grocery list."));
        }
Ejemplo n.º 7
0
        void AddRecepieToGroceryList(Recepie rec)
        {
            if (rec == null)
            {
                return;
            }

            foreach (Ingredient ing in rec.Ingredients)
            {
                if (!inList.Contains(ing.Name))
                {
                    inList.Add(ing.Name);
                    GroceryList.Add(new Ingredient(ing.Name, ing.Count, ing.Units));
                }
                else
                {
                    for (int k = 0; k < GroceryList.Count; k++)
                    {
                        if (GroceryList[k].Name == ing.Name)
                        {
                            GroceryList[k].SumIngredient(ing);
                            k = GroceryList.Count;
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public async Task <GroceryList> Add(GroceryList groceryList)
        {
            groceryList.CreatedDate = DateTime.Now.ToUniversalTime();
            groceryList.IsComplete  = false;

            return(await _groceryListRepository.Add(groceryList));
        }
        /* Author: Anders Long
         * This function, given a groceryListId, and a new list, containing all
         * edited properties, applies these properties to the record in the DB.
         *
         */
        public void Edit(int groceryListId, GroceryList newGroceryList)
        {
            var groceryListsInDb = this.Get(groceryListId);

            groceryListsInDb.Title = newGroceryList.Title;
            _context.SaveChanges();
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> PutGroceryList(int id, GroceryList groceryList)
        {
            if (id != groceryList.Id)
            {
                return(BadRequest());
            }

            _context.Entry(groceryList).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GroceryListExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> Edit(int id, [Bind("UserId,ListItem,UserName")] GroceryList groceryList)
        {
            if (id != groceryList.UserId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(groceryList);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GroceryListExists(groceryList.UserId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(groceryList));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Método para mostrar los productos en la Grocery List
        /// </summary>
        /// <returns>Una lista de los productos que hay en la BD en la tabla personal</returns>
        public List <GroceryList> GroceryList()
        {
            using (IDbConnection Conexion = DbConection.Conexion())
            {
                Conexion.Open();

                SqlCommand command = new SqlCommand("spGetGroceryList", Conexion as SqlConnection);
                command.CommandType = CommandType.StoredProcedure;

                IDataReader productsReader = command.ExecuteReader();

                List <GroceryList> lstProductsPersonal = new List <GroceryList>();

                while (productsReader.Read())
                {
                    GroceryList objListProductPersonal = new GroceryList();

                    objListProductPersonal.idProducto  = Convert.ToInt32(productsReader["idProducto"]);
                    objListProductPersonal.Tag         = Convert.ToBoolean(productsReader["Tag"]);
                    objListProductPersonal.NameProduct = Convert.ToString(productsReader["NameProduct"]);
                    objListProductPersonal.Cod         = Convert.ToInt32(productsReader["Cod"]);
                    objListProductPersonal.Price       = Convert.ToInt32(productsReader["Price"]);

                    lstProductsPersonal.Add(objListProductPersonal);
                }

                return(lstProductsPersonal);
            }
        }
        public void Delete(int id)
        {
            GroceryList groceryList = _db.GroceryLists.Find(id);

            _db.GroceryLists.Remove(groceryList);
            _db.SaveChanges();
        }
Ejemplo n.º 14
0
        public ActionResult DeleteConfirmed(int id)
        {
            GroceryList groceryList = db.GroceryLists.Find(id);

            db.GroceryLists.Remove(groceryList);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 15
0
        public static void Invite(UIViewController view, GroceryList list, string inviteeEmail)
        {
            User inviteeUser = null;
            var  inviterUser = AppData.currentUser;
            var  listName    = list.ListName;

            AppData.UsersNode.ObserveSingleEvent(DataEventType.Value, snapshot =>
            {
                var children      = snapshot.Children;
                var childSnapShot = children.NextObject() as DataSnapshot;

                while (childSnapShot != null)
                {
                    var childDict = childSnapShot.GetValue <NSDictionary>();

                    if (childDict.ValueForKey((NSString)"email").ToString() == inviteeEmail)
                    {
                        // user exist
                        inviteeUser = new User
                        {
                            Name  = childDict.ValueForKey((NSString)"name").ToString(),
                            Email = childDict.ValueForKey((NSString)"email").ToString(),
                            Uid   = childDict.ValueForKey((NSString)"uid").ToString()
                        };
                        break;
                    }
                    childSnapShot = children.NextObject() as DataSnapshot;
                }


                if (inviteeUser == null)
                {
                    CustomAlert.Alert(view,
                                      "No Such User",
                                      "Such user doesn't have an account with us");
                    return;
                }

                var invitationTitle = inviterUser.Uid + "|" + listName;

                object[] ownerKeys   = { "ownerUid", "ownerEmail", "ownerName" };
                object[] ownerValues = { inviterUser.Uid, inviterUser.Email, inviterUser.Name };
                var ownerDict        = NSDictionary.FromObjectsAndKeys(ownerValues, ownerKeys);

                object[] inviteeKeys   = { "listName", "owner" };
                object[] inviteeValues = { listName, ownerDict };
                var inviteeDict        = NSDictionary.FromObjectsAndKeys(inviteeValues, inviteeKeys);

                var inviteeNode = AppData.UsersNode.GetChild(inviteeUser.Uid);
                inviteeNode.GetChild("myInvitations")
                .GetChild(invitationTitle)
                .SetValue(inviteeDict);

                CustomAlert.Alert(view,
                                  "Invitation Sent",
                                  "You have successfully invited " + inviteeUser.Name + " to this list.");
            });
        }
        public void addGroceryListItem(GroceryList g, Item i)
        {
            GroceryListItem gi = new GroceryListItem();

            gi.GroceryList = g;
            gi.Item        = i;
            _groceryContext.GroceryListItems.Add(gi);
            _groceryContext.SaveChanges();
        }
Ejemplo n.º 17
0
 public IActionResult Edit(GroceryList groceryList)
 {
     if (ModelState.IsValid)
     {
         _groceryLists.UpdateGroceryList(groceryList.Id, groceryList);
         return(RedirectToAction("Index", "Home"));
     }
     return(View(groceryList));
 }
 public ActionResult Post([FromBody] GroceryList g)
 {
     if (g == null)
     {
         return(BadRequest("Grocery List is null"));
     }
     _groceryRepository.addGroceryList(g);
     return(NoContent());
 }
        public GroceryList getGroceryList(int id)
        {
            GroceryList g = _groceryContext.GroceryLists.Where(p => p.GroceryListId == id).FirstOrDefault();

            //g.GroceryListItems



            return(g);
        }
Ejemplo n.º 20
0
 public ActionResult Edit([Bind(Include = "Id,NameOfIngredient,BuyAmount")] GroceryList groceryList)
 {
     if (ModelState.IsValid)
     {
         db.Entry(groceryList).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(groceryList));
 }
Ejemplo n.º 21
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl      = returnUrl ?? Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = Input.Email, Email = Input.Email,
                    Name     = Input.Name
                };
                var pantry = new Pantry();

                _context.Pantries.Add(pantry);

                await _context.SaveChangesAsync();

                user.PantryId = pantry.Id;
                var groceryList = new GroceryList()
                {
                    PantryId = pantry.Id
                };
                _context.GroceryLists.Add(groceryList);

                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");


                    await _signInManager.SignInAsync(user, isPersistent : false);

                    return(LocalRedirect(returnUrl));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Ejemplo n.º 22
0
        public ActionResult Create([Bind(Include = "Id,NameOfIngredient,BuyAmount")] GroceryList groceryList)
        {
            if (ModelState.IsValid)
            {
                db.GroceryLists.Add(groceryList);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(groceryList));
        }
Ejemplo n.º 23
0
        public async Task <IActionResult> Create([Bind("UserId,ListItem,UserName")] GroceryList groceryList)
        {
            if (ModelState.IsValid)
            {
                _context.Add(groceryList);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(groceryList));
        }
Ejemplo n.º 24
0
        public async Task <GroceryList> Delete(GroceryList groceryList)
        {
            var current = await _groceryListRepository.Get(groceryList.Id);

            if (current.UserId != _userService.CurrentUserId)
            {
                throw new UnauthorizedAccessException();
            }

            return(await _groceryListRepository.Delete(groceryList.Id));
        }
Ejemplo n.º 25
0
    public void SwapGreenTick(GroceryList item)
    {
        // this method swaps out red cross for green tick to indicate to player they have picked up the item

        int index = (int)item;

        //crossTickImg[index].sprite = greenTick;
        itemPickedUp[index] = true;

        Debug.Log("Swap function called");
    }
Ejemplo n.º 26
0
        public void DeleteIngredient()
        {
            List <Ingredient> list = new List <Ingredient>();

            GroceryList.Remove(SelectedIngredient);
            foreach (var ing in GroceryList)
            {
                list.Add(ing);
            }
            GroceryList = list;
        }
Ejemplo n.º 27
0
        /// <summary>
        /// This updates the grocery list to a new state.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="gl"></param>
        public void UpdateGroceryList(int id, GroceryList gl)
        {
            var oldList = ReadGroceryList(id);

            if (oldList != null)
            {
                oldList.GroceryItems    = gl.GroceryItems;
                oldList.GroceryListName = gl.GroceryListName;
                oldList.OwnerId         = gl.OwnerId;
                _db.SaveChanges();
            }
        }
Ejemplo n.º 28
0
        //Create a grocery list
        public async Task <bool> CreateGroceryList(GroceryCreate model)
        {
            var entity =
                new GroceryList()
            {
                OwnerId = _userId,
                Name    = model.Name,
            };

            _context.GroceryLists.Add(entity);
            return(await _context.SaveChangesAsync() == 1);
        }
Ejemplo n.º 29
0
        public IActionResult GetById(long id)
        {
            Entity      entity = _db.Lookup(_keyFactory.CreateKey(id));
            GroceryList item   = new GroceryList()
            {
                GroceryListId = entity.Key.Path[0].Id.ToString(), UserId = (string)entity["UserId"], GroceryName = (string)entity["GroceryName"], Quantity = (string)entity["Quantity"], Shareable = (bool)entity["Shareable"]
            };

            JsonResult jsonItem = new JsonResult(item);

            return(jsonItem);
        }
Ejemplo n.º 30
0
        public static void GetItemDetails()
        {
            var product = new CartItem();

            CreateProduct(product);

            SubTotal += product.Quantity * product.Price;

            ConsoleLogging.IsImported(product);
            ConsoleLogging.IsTaxable(product);

            GroceryList.Add(product);
        }