コード例 #1
0
 public List <Wish> ListarPorUser(int userId)
 {
     using (WishListContext ctx = new WishListContext())
     {
         return(ctx.Wish.Where(x => x.WishOwnerId == userId).ToList());
     }
 }
コード例 #2
0
 public Wish BuscarWishPorId(int WishId)
 {
     using (WishListContext ctx = new WishListContext())
     {
         return(ctx.Wish.Find(WishId));
     }
 }
コード例 #3
0
        public ActionResult AddToWishList(int UserId, int BookId)
        {
            WishListContext wishListContext = new WishListContext();
            List <WishList> wishList        = wishListContext.WishLists.Where(entity => entity.CustomerId == UserId).ToList();
            bool            presence        = false;

            foreach (var item in wishList)
            {
                if (item.Bookid == BookId)
                {
                    presence = true;
                    break;
                }
                else
                {
                    presence = false;
                }
            }
            if (presence == true)
            {
                return(Content("Book is already available in wishlist. Please go back"));
            }
            else
            {
                WishList wishList1 = new WishList {
                    CustomerId = UserId, Bookid = BookId
                };
                wishListContext.WishLists.Add(wishList1);
                wishListContext.SaveChanges();
                return(RedirectToAction("ListBook", new { id = UserId }));
            }
        }
コード例 #4
0
 public Users BuscarPorEmailESenha(LoginViewModel login)
 {
     using (WishListContext ctx = new WishListContext())
     {
         return(ctx.Users.FirstOrDefault(x => x.UserEmail == login.Email && x.UserSenha == login.Senha));
     }
 }
コード例 #5
0
ファイル: HomeController.cs プロジェクト: TigerLeep/wishlist
        public ActionResult MoveItemDown(int id)
        {
            var context = new WishListContext();
            var item    = (from i in context.Items
                           where i.Id == id
                           select i)
                          .SingleOrDefault();

            if (item == null)
            {
                return(RedirectToAction("List", new { id = item.UserId }));
            }

            var nextItem = (from i in context.Items
                            where i.Order > item.Order &&
                            i.UserId == item.UserId
                            orderby i.Order
                            select i)
                           .FirstOrDefault();

            if (nextItem == null)
            {
                return(RedirectToAction("List", new { id = item.UserId }));
            }
            var order = item.Order;

            item.Order     = nextItem.Order;
            nextItem.Order = order;
            context.SaveChanges();
            return(RedirectToAction("List", new { id = item.UserId }));
        }
コード例 #6
0
 public List <Wish> ListarTodos()
 {
     using (WishListContext ctx = new WishListContext())
     {
         return(ctx.Wish.ToList());
     }
 }
コード例 #7
0
 public Users BuscarPorId(int userId)
 {
     using (WishListContext ctx = new WishListContext())
     {
         return(ctx.Users.FirstOrDefault(x => x.UserId == userId));
     }
 }
コード例 #8
0
 public void CadastrarUser(Users usuario)
 {
     using (WishListContext ctx = new WishListContext())
     {
         ctx.Users.Add(usuario);
         ctx.SaveChanges();
     }
 }
コード例 #9
0
 public void Atualizar(Wish newWish, Wish oldWish)
 {
     using (WishListContext ctx = new WishListContext())
     {
         ctx.Wish.Update(oldWish);
         ctx.SaveChanges();
     }
 }
コード例 #10
0
ファイル: HomeController.cs プロジェクト: TigerLeep/wishlist
        public ActionResult Index()
        {
            var context = new WishListContext();
            var users   = from u in context.Users
                          orderby u.Name
                          select u;

            return(View(users.ToList()));
        }
コード例 #11
0
 public void CadastrarWish(Wish wish, int userId)
 {
     using (WishListContext ctx = new WishListContext())
     {
         wish.WishOwnerId  = userId;
         wish.WishCreation = DateTime.Now;
         ctx.Wish.Add(wish);
         ctx.SaveChanges();
     }
 }
コード例 #12
0
        public void Cadastrar(DesejoViewModel desejo)
        {
            Desejo desejoDomain = new Desejo(desejo.Nome, desejo.Descricao, desejo.Usuarioid);

            using (WishListContext ctx = new WishListContext())
            {
                ctx.Add(desejoDomain);
                ctx.SaveChanges();
            }
        }
コード例 #13
0
        public WishListController(WishListContext context)
        {
            _context = context;

            //if (_context.WishLists.Count() == 0)
            //{
            //_context.WishLists.Add(new WishList { Title = "Item1", DateOfEvent = DateTime.Now, OwnerID = 1});
            //    _context.WishLists.Add(new WishList { Title = "Item2" });
            //_context.SaveChanges();
            //}
        }
コード例 #14
0
        public List <Desejo> Listar()
        {
            using (WishListContext ctx = new WishListContext())
            {
                if (ctx.Desejos.Count() > 0)
                {
                    return(ctx.Desejos.ToList());
                }
            }

            throw new Exception("Não existe nenhum desejo cadastrado no banco de dados");
        }
コード例 #15
0
        public WishController(WishListContext context)
        {
            _context = context;

            if (_context.Wishes.Count() == 0)
            {
                _context.Wishes.Add(new Wish {
                    WishListID = 3, Title = "Wish 1", IsChecked = false, ImageURL = "https://i.imgur.com/wKjdA9G.jpg", Categorie = WishCategorie.ANDERE, BuyerID = 1, Description = "Corgi with a plant on his head"
                });
                _context.SaveChanges();
            }
        }
コード例 #16
0
ファイル: HomeController.cs プロジェクト: TigerLeep/wishlist
        public ActionResult Edit(int id)
        {
            var context = new WishListContext();
            var query   = (from i in context.Items
                           where i.Id == id
                           select new { User = i.User, Item = i })
                          .SingleOrDefault();
            var editViewModel = new EditViewModel()
            {
                User = query.User,
                Item = query.Item
            };

            return(View(editViewModel));
        }
コード例 #17
0
ファイル: HomeController.cs プロジェクト: TigerLeep/wishlist
        public ActionResult Delete(int id, int userId)
        {
            var context = new WishListContext();
            var item    = (from i in context.Items
                           where i.Id == id
                           select i)
                          .SingleOrDefault();

            if (item != null)
            {
                context.Items.Remove(item);
                context.SaveChanges();
            }
            return(RedirectToAction("List", new { id = userId }));
        }
コード例 #18
0
ファイル: HomeController.cs プロジェクト: TigerLeep/wishlist
        public ActionResult Edit(Item item, int userId)
        {
            var context  = new WishListContext();
            var editItem = (from i in context.Items
                            where i.Id == item.Id
                            select i)
                           .SingleOrDefault();

            if (editItem != null)
            {
                editItem.Description = item.Description;
                context.SaveChanges();
            }

            return(RedirectToAction("List", new { id = userId }));
        }
        public Usuario Login(string email, string senha)
        {
            using (WishListContext ctx = new WishListContext())
            {
                Usuario usuario = ctx.Usuarios
                                  .ToList()
                                  .FirstOrDefault(x => x.Email == email && x.Senha == senha);

                if (usuario != null)
                {
                    return(usuario);
                }
            }

            throw new NullReferenceException("Email ou senha invalidos");
        }
        public Usuario ListarDesejos(int usuarioId)
        {
            using (WishListContext ctx = new WishListContext())
            {
                Usuario usuario = ctx.Usuarios
                                  .Include(x => x.Desejos)
                                  .First(x => x.Id == usuarioId);

                if (usuario != null)
                {
                    return(usuario);
                }
            }

            throw new NullReferenceException("Erro ao encontrar usuario");
        }
コード例 #21
0
ファイル: HomeController.cs プロジェクト: TigerLeep/wishlist
        public ActionResult Create(int id)
        {
            var context = new WishListContext();
            var user    = (from u in context.Users
                           where u.Id == id
                           select u)
                          .SingleOrDefault();
            var item            = new Item();
            var createViewModel = new CreateViewModel()
            {
                User = user,
                Item = item
            };

            return(View(createViewModel));
        }
コード例 #22
0
        private void SeedIndexerDatabase(WishListContext wishListContext)
        {
            var indexContext = serviceProvider.GetService <IndexContext>();

            indexContext.DeleteIndex <ProductModel>();
            indexContext.DeleteIndex <UserModel>();
            indexContext.DeleteIndex <WishModel>();

            indexContext.ExecuteMappings();

            indexContext.BulkInsert(wishListContext.Users.Select(x => new UserModel {
                Id = x.Id, Email = x.Email, Name = x.Name
            }));
            indexContext.BulkInsert(wishListContext.Products.Select(x => new ProductModel {
                Id = x.Id, Name = x.Name
            }));
        }
コード例 #23
0
ファイル: HomeController.cs プロジェクト: TigerLeep/wishlist
        public ActionResult List(int id)
        {
            var context = new WishListContext();
            var user    = (from u in context.Users
                           where u.Id == id
                           select u)
                          .SingleOrDefault();
            var items = (from i in context.Items
                         where i.UserId == id
                         orderby i.Order
                         select i)
                        .ToList();
            var listViewModel = new ListViewModel()
            {
                User  = user,
                Items = items.ToList()
            };

            return(View(listViewModel));
        }
        public void Cadastrar(UsuarioViewModel usuario)
        {
            using (WishListContext ctx = new WishListContext())
            {
                bool emailExiste = ctx.Usuarios.Any(x => x.Email == usuario.Email);

                if (!emailExiste)
                {
                    Usuario usuarioDomain = new Usuario(usuario.Nome, usuario.Email, usuario.Senha);

                    ctx.Usuarios.Add(usuarioDomain);

                    ctx.SaveChanges();
                }
                else
                {
                    throw new NullReferenceException("Email ja está em uso");
                }
            }
        }
コード例 #25
0
        public ActionResult ViewWishList(int UserId)
        {
            WishListContext wishListContext = new WishListContext();
            BookData        bookDataContext = new BookData();
            List <WishList> wishLists       = wishListContext.WishLists.Where(entity => entity.CustomerId == UserId).ToList();
            List <BookDb>   bookDbs         = new List <BookDb>();

            if (wishLists != null)
            {
                foreach (var item in wishLists)
                {
                    BookDb bookDb = bookDataContext.BookDbs.SingleOrDefault(entity => entity.id == item.Bookid);
                    bookDbs.Add(bookDb);
                }
            }
            else
            {
                return(Content("WishList is Empty"));
            }
            ViewBag.userid = UserId;
            return(View(bookDbs));
        }
コード例 #26
0
 public ActionResult RemoveFromWishList(int UserId, int BookId)
 {
     try
     {
         WishListContext wishListContext = new WishListContext();
         List <WishList> wishList        = wishListContext.WishLists.Where(entity => entity.CustomerId == UserId).ToList();
         foreach (var item in wishList)
         {
             if (item.Bookid == BookId)
             {
                 wishListContext.WishLists.Remove(item);
                 wishListContext.SaveChanges();
                 return(RedirectToAction("ViewWishList", new { UserId = UserId }));
             }
         }
         return(null);
     }
     catch (Exception e)
     {
         return(Content("Unable to delete due to " + Convert.ToString(e)));
     }
 }
コード例 #27
0
ファイル: HomeController.cs プロジェクト: TigerLeep/wishlist
        public ActionResult Create(int id, Item item)
        {
            var context = new WishListContext();
            var items   = context.Items
                          .Where(i => i.UserId == id);
            var maxOrder = 0M;

            if (items.Any())
            {
                maxOrder = items.Max(i => i.Order);
            }
            var newItem = new Item()
            {
                Description = item.Description,
                Order       = maxOrder + 1,
                UserId      = id
            };

            context.Items.Add(newItem);
            context.SaveChanges();

            return(RedirectToAction("List", new { id = id }));
        }
コード例 #28
0
 public AppController(WishListContext ctx)
 {
     _ctx = ctx;
 }
コード例 #29
0
 public WishListRepository(WishListContext context)
 {
     _context = context;
 }
コード例 #30
0
 public WishListSeed(WishListContext context, UserManager <WishListUser> userManager)
 {
     _context     = context;
     _userManager = userManager;
 }