示例#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));
     }
 }
        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
        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
        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
        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
        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
        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
        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
        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");
                }
            }
        }
        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));
        }
 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
        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;
 }