public void Edit(ShoppingList p)
 {
     utOfWork.ShoppingListRepository.Update(p);
     utOfWork.Commit();
 }
        // POST: odata/ShoppingLists
        public IHttpActionResult Post(ShoppingList shoppingList)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.ShoppingList.Add(shoppingList);
            db.SaveChanges();

            return Created(shoppingList);
        }
 public void AddNew(ShoppingList p)
 {
     utOfWork.ShoppingListRepository.Add(p);
     utOfWork.Commit();
 }
        public ActionResult Index(ShoppingList sl)
        {
            if (Session["User"] != null)
            {
                Client Client = Session["User"] as Client;
            }
            else
            {
                return RedirectToAction("LoginClient", "Home");
            }

            sl.Finished = false;
            Client c = Session["User"] as Client;
            sl.ClientId = c.Id;
            if (sl.Private == null)
            {
                sl.Private = false;
            }
            if (sl.Name == null || sl.Name == "")
            {
                Random _rng = new Random();
                string _chars = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                int size = 7;
                char[] buffer = new char[size];

                for (int i = 0; i < size; i++)
                {
                    buffer[i] = _chars[_rng.Next(_chars.Length)];
                }
                sl.Name = new string(buffer);
            }

            ShoppingListService.AddNew(sl);
            List<ShoppingList> l = ShoppingListService.GetAll().ToList();
            ShoppingList flist = new ShoppingList();
            foreach (var item in l)
            {
                if (item.ClientId == sl.ClientId && item.Name == sl.Name)
                {
                    flist = item;
                    break;
                }
            }
            if (flist == null)
            {
                ViewBag.Error = "Failed to add list";
                return RedirectToAction("Index", "Home");
            }
            else
            {
                Session["ShoppingList"] = flist;
                return RedirectToAction("NewList", "Home");
            }
        }