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)); }
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 })); } } }
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 })); } } }
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()); } } } }
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(); } }
public void Cadastrar(Usuarios usuario) { using (WishlistContext ctx = new WishlistContext()) { ctx.Add(usuario); ctx.SaveChanges(); } }
public void Cadastrar(Desejos desejo) { desejo.Datacriacao = DateTime.Now; using (WishlistContext ctx = new WishlistContext()) { ctx.Desejos.Add(desejo); ctx.SaveChanges(); } }
public void Deletar(int id) { using (WishlistContext ctx = new WishlistContext()) { Desejos desejo = ctx.Desejos.Find(id); ctx.Desejos.Remove(desejo); ctx.SaveChanges(); } }
public void Deletar(int id) { using (WishlistContext ctx = new WishlistContext()) { Usuarios usuarioProcurado = ctx.Usuarios.Find(id); ctx.Usuarios.Remove(usuarioProcurado); ctx.SaveChanges(); } }
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(); } }
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")); }
//[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()); }
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(); } }
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)); }
/// <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(); }
public void Save() { _dbContext.SaveChanges(); }
public void CadastrarUsuario(Usuarios usuario) { ctx.Usuarios.Add(usuario); ctx.SaveChanges(); }
/// <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(); }