public IActionResult Create([FromBody] Wish item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

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

            return(CreatedAtRoute("GetWish", new { id = item.Id }, item));
        }
예제 #2
0
        public ActionResult ChangeWishlist(WishlistJsonModel model)
        {
            using (var db = new WishlistContext())
            {
                var wl = db.Wishlists.FirstOrDefault(wl2 => wl2.WishlistId == model.ID);

                if (wl == null)
                {
                    return(Json(new
                    {
                        Success = false,
                        Exception = "Invalid wishlist id."
                    }));
                }
                else if (wl.UserId != WebSecurity.CurrentUserId)
                {
                    return(Json(new
                    {
                        Success = false,
                        Exception = "Change requested by an unauthorized user."
                    }));
                }
                else
                {
                    wl.WishlistTitle = model.Title;
                    wl.IsPublic      = model.IsPublic;
                    db.SaveChanges();
                    return(Json(new
                    {
                        Success = true
                    }));
                }
            }
        }
예제 #3
0
        public ActionResult RemoveWishlistItem(WishlistItemIDModel wlireq)
        {
            using (var db = new WishlistContext())
            {
                var wli = db.WishlistItems.FirstOrDefault(wli2 => wli2.WishlistItemId == wlireq.ID);

                if (wli == null)
                {
                    return(Json(new
                    {
                        Success = false,
                        Exception = "Invalid wishlist item id."
                    }));
                }
                else if (wli.Wishlist.UserId != WebSecurity.CurrentUserId)
                {
                    return(Json(new
                    {
                        Success = false,
                        Exception = "Removal requested by an unauthorized user."
                    }));
                }
                else
                {
                    db.WishlistItems.Remove(wli);
                    db.SaveChanges();

                    return(Json(new
                    {
                        Success = true
                    }));
                }
            }
        }
예제 #4
0
        public ActionResult ChangeProfilePhoto(HttpPostedFileBase image)
        {
            using (var db = new WishlistContext())
            {
                var userID = WebSecurity.CurrentUserId;
                var user   = db.webpages_Membership.FirstOrDefault(u => u.UserId == userID);

                if (user == null)
                {
                    ModelState.AddModelError("", "The current user does not exist.");
                    return(View());
                }
                else
                {
                    try
                    {
                        var origImg = new Image(image.InputStream);
                        var img128  = origImg.Resize(128, 128).SerializeJpeg();
                        var img32   = origImg.Resize(32, 32).SerializeJpeg();
                        user.ProfilePicture128 = img128;
                        user.ProfilePicture32  = img32;
                        db.SaveChanges();
                        return(RedirectToAction("Manage", new { Message = ManageMessageId.ChangeProfilePhotoSuccess }));
                    }
                    catch (Exception ex)
                    {
                        ModelState.AddModelError("", ex.Message);
                        return(View());
                    }
                }
            }
        }
예제 #5
0
        public ActionResult NewWishlist()
        {
            using (var db = new WishlistContext())
            {
                var wl = new Models.Wishlist
                {
                    UserId        = WebSecurity.CurrentUserId,
                    WishlistTitle = "New Wishlist"
                };
                db.Wishlists.Add(wl);
                db.SaveChanges();

                return(Json(new
                {
                    Success = true,
                    Result = new WishlistFullJsonModel
                    {
                        Info = new WishlistJsonModel
                        {
                            ID = wl.WishlistId,
                            Title = wl.WishlistTitle,
                            IsPublic = wl.IsPublic
                        },
                        WishlistItems = new WishlistItemJsonModel[] { }
                    }
                }));
            }
        }
 public void DeletarDesejo(Desejos desejo)
 {
     using (WishlistContext ctx = new WishlistContext())
     {
         ctx.Desejos.Remove(desejo);
         ctx.SaveChanges();
     }
 }
 public void CadastrarDesejo(Desejos desejo)
 {
     using (WishlistContext ctx = new WishlistContext())
     {
         ctx.Desejos.Add(desejo);
         ctx.SaveChanges();
     }
 }
예제 #8
0
 public void Cadastrar(Usuarios usuario)
 {
     using (WishlistContext ctx = new WishlistContext())
     {
         ctx.Add(usuario);
         ctx.SaveChanges();
     }
 }
예제 #9
0
        public void Cadastrar(Desejos desejo)
        {
            desejo.Datacriacao = DateTime.Now;

            using (WishlistContext ctx = new WishlistContext())
            {
                ctx.Desejos.Add(desejo);
                ctx.SaveChanges();
            }
        }
예제 #10
0
        public void Deletar(int id)
        {
            using (WishlistContext ctx = new WishlistContext())
            {
                Desejos desejo = ctx.Desejos.Find(id);

                ctx.Desejos.Remove(desejo);
                ctx.SaveChanges();
            }
        }
예제 #11
0
        public void Deletar(int id)
        {
            using (WishlistContext ctx = new WishlistContext())
            {
                Usuarios usuarioProcurado = ctx.Usuarios.Find(id);

                ctx.Usuarios.Remove(usuarioProcurado);
                ctx.SaveChanges();
            }
        }
예제 #12
0
        public ActionResult RoleCreate(string roleName)
        {
            using (var context = new WishlistContext())
            {
                var roleStore   = new RoleStore <IdentityRole>(context);
                var roleManager = new RoleManager <IdentityRole>(roleStore);

                roleManager.Create(new IdentityRole(roleName));
                context.SaveChanges();
            }

            ViewBag.ResultMessage = "Role created successfully !";
            return(RedirectToAction("RoleIndex", "Account"));
        }
        public void AtualizarDesejo(Desejos desejoCadastrado, Desejos desejoNovo)
        {
            if (desejoNovo.Descricao != null)
            {
                desejoCadastrado.Descricao = desejoNovo.Descricao;
            }

            desejoCadastrado.DataCriacao = DateTime.Now;

            using (WishlistContext ctx = new WishlistContext())
            {
                ctx.Desejos.Update(desejoCadastrado);
                ctx.SaveChanges();
            }
        }
예제 #14
0
        public ActionResult DeleteRoleForUser(string userName, string roleName)
        {
            List <string> userRoles;
            List <string> roles;
            List <string> users;

            using (var context = new WishlistContext())
            {
                var roleStore   = new RoleStore <IdentityRole>(context);
                var roleManager = new RoleManager <IdentityRole>(roleStore);

                roles = (from r in roleManager.Roles select r.Name).ToList();

                var userStore   = new UserStore <WishlistUser>(context);
                var userManager = new UserManager <WishlistUser>(userStore);

                users = (from u in userManager.Users select u.UserName).ToList();

                var user = userManager.FindByName(userName);
                if (user == null)
                {
                    throw new Exception("User not found!");
                }

                if (userManager.IsInRole(user.Id, roleName))
                {
                    userManager.RemoveFromRole(user.Id, roleName);
                    context.SaveChanges();

                    ViewBag.ResultMessage = "Role removed from this user successfully !";
                }
                else
                {
                    ViewBag.ResultMessage = "This user doesn't belong to selected role.";
                }

                var userRoleIds = (from r in user.Roles select r.RoleId);
                userRoles = (from id in userRoleIds
                             let r = roleManager.FindById(id)
                                     select r.Name).ToList();
            }

            ViewBag.RolesForThisUser = userRoles;
            ViewBag.Roles            = new SelectList(roles);
            ViewBag.Users            = new SelectList(users);
            return(View("RoleAddToUser"));
        }
예제 #15
0
        //[ValidateAntiForgeryToken]
        public ActionResult RoleAddToUser(string roleName, string userName)
        {
            List <string> roles;
            List <string> users;

            using (var context = new WishlistContext())
            {
                var roleStore   = new RoleStore <IdentityRole>(context);
                var roleManager = new RoleManager <IdentityRole>(roleStore);

                var userStore   = new UserStore <WishlistUser>(context);
                var userManager = new UserManager <WishlistUser>(userStore);

                users = (from u in userManager.Users select u.UserName).ToList();

                var user = userManager.FindByName(userName);
                if (user == null)
                {
                    throw new Exception("User not found!");
                }

                var role = roleManager.FindByName(roleName);
                if (role == null)
                {
                    throw new Exception("Role not found!");
                }

                if (userManager.IsInRole(user.Id, role.Name))
                {
                    ViewBag.ResultMessage = "This user already has the role specified !";
                }
                else
                {
                    userManager.AddToRole(user.Id, role.Name);
                    context.SaveChanges();

                    ViewBag.ResultMessage = "Username added to the role succesfully !";
                }

                roles = (from r in roleManager.Roles select r.Name).ToList();
            }

            ViewBag.Roles = new SelectList(roles);
            ViewBag.Users = new SelectList(users);
            return(View());
        }
예제 #16
0
        public ActionResult NewWishlistItem(WishlistIDModel wlreq)
        {
            using (var db = new WishlistContext())
            {
                var wl = db.Wishlists.FirstOrDefault(wl2 => wl2.WishlistId == wlreq.ID);

                if (wl == null)
                {
                    return(Json(new
                    {
                        Success = false,
                        Exception = "Invalid wishlist id."
                    }));
                }
                else if (wl.UserId != WebSecurity.CurrentUserId)
                {
                    return(Json(new
                    {
                        Success = false,
                        Exception = "Add requested by an unauthorized user."
                    }));
                }
                else
                {
                    var wli = new Models.WishlistItem
                    {
                        WishlistId          = wl.WishlistId,
                        WishlistItemContent = "New Wishlist Item"
                    };

                    db.WishlistItems.Add(wli);
                    db.SaveChanges();

                    return(Json(new
                    {
                        Success = true,
                        Result = new WishlistItemJsonModel
                        {
                            ID = wli.WishlistItemId,
                            Content = wli.WishlistItemContent
                        }
                    }));
                }
            }
        }
        public WishlistController(WishlistContext context)
        {
            _context = context;

            if (_context.Wishes.Count() == 0)
            {
                var wish = new Wish
                {
                    Name         = "Sonos Playbar lydplanke",
                    Price        = 6998,
                    Url          = "http://www.vg.no",
                    NumberBought = 0,
                    NumberWished = 1
                };

                _context.Wishes.Add(wish);
                _context.SaveChanges();
            }
        }
예제 #18
0
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider       = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return(RedirectToAction("Manage"));
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (var db = new WishlistContext())
                {
                    UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.UserProfiles.Add(new UserProfile {
                            UserName = model.UserName
                        });
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return(RedirectToLocal(returnUrl));
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl           = returnUrl;
            return(View(model));
        }
예제 #19
0
 /// <summary>
 /// Cadastra um novo tipo de usuário
 /// </summary>
 /// <param name="tipoUsuario">Recebe um objeto tipoUsuario</param>
 public void CadastarTipoUsuario(TiposUsuarios tipoUsuario)
 {
     // Adiciona tipo de usuário recebido e salva no banco
     ctx.TiposUsuarios.Add(tipoUsuario);
     ctx.SaveChanges();
 }
예제 #20
0
 public void Save()
 {
     _dbContext.SaveChanges();
 }
예제 #21
0
 public void CadastrarUsuario(Usuarios usuario)
 {
     ctx.Usuarios.Add(usuario);
     ctx.SaveChanges();
 }
예제 #22
0
 /// <summary>
 /// Cadastra um novo desejo
 /// </summary>
 /// <param name="desejo">Recebe um objeto desejo</param>
 public void CadastrarDesejo(Desejos desejo)
 {
     // Adiciona o desejo e salva no banco
     ctx.Desejos.Add(desejo);
     ctx.SaveChanges();
 }