public async Task <ActionResult> RemoveCollaborator(RemovedCollaborator removedCollaborator) { // Make sure we are the owner of the list if (!await unitOfWork.Collaborators.Any(x => x.ListId == removedCollaborator.ListId && x.CustomerId == User.FindFirst(ClaimTypes.NameIdentifier).Value&& x.IsOwner)) { return(Unauthorized()); } // Get the collaborator to remove ListCollaborator collaborator = await unitOfWork.Collaborators.Get(x => x.Id == removedCollaborator.Id && x.ListId == removedCollaborator.ListId); // If found, mark the collaborator as removed if (collaborator != null) { collaborator.IsRemoved = true; unitOfWork.Collaborators.Update(collaborator); await unitOfWork.Save(); // Setup the email emailService.SetupEmail(SetupRemovedCollaborator, new EmailSetupParams { Host = GetHost(), CollaboratorId = collaborator.Id, ListId1 = removedCollaborator.ListId }); return(Ok()); } return(NotFound()); }
public async Task <ActionResult> Register(Account account) { Customer customer = account.CreateCustomer(); // Add the new customer to the database IdentityResult result = await userManager.CreateAsync(customer, account.Password); if (result.Succeeded) { // Send an email to activate the account await SendAccountActivationEmail(customer); // Create the new list and add it to the database List newList = new List { Id = Guid.NewGuid().ToString("N").Substring(0, 10).ToUpper(), Name = "My List", Description = string.Empty, CollaborateId = Guid.NewGuid().ToString("N").Substring(0, 10).ToUpper() }; unitOfWork.Lists.Add(newList); // Set the owner as the first collaborator of the list ListCollaborator collaborator = new ListCollaborator { CustomerId = customer.Id, ListId = newList.Id, IsOwner = true }; unitOfWork.Collaborators.Add(collaborator); // Save all updates to the database await unitOfWork.Save(); // The new customer was successfully added to the database return(Ok()); } else { string error = string.Empty; if (result.Errors.Count(x => x.Code == "DuplicateEmail") == 1) { error = "The email address, \"" + account.Email.ToLower() + ",\" already exists with another Niche Shack account. Please use another email address."; } return(Conflict(error)); } }
public async Task <ActionResult> Register(Account account) { Customer customer = account.CreateCustomer(); // Add the new customer to the database IdentityResult result = await userManager.CreateAsync(customer, account.Password); if (result.Succeeded) { // Create the new list and add it to the database List newList = new List { Id = Guid.NewGuid().ToString("N").ToUpper(), Name = "Wish List", Description = string.Empty, CollaborateId = Guid.NewGuid().ToString("N").ToUpper() }; unitOfWork.Lists.Add(newList); // Set the owner as the first collaborator of the list ListCollaborator collaborator = new ListCollaborator { Id = Guid.NewGuid(), CustomerId = customer.Id, ListId = newList.Id, IsOwner = true }; unitOfWork.Collaborators.Add(collaborator); // Save all updates to the database await unitOfWork.Save(); // The new customer was successfully added to the database return(Ok()); } else { // There was a problem adding the customer to the database. Return with errors foreach (IdentityError error in result.Errors) { if (error.Code == "DuplicateEmail") { error.Description = "The email address, \"" + account.Email.ToLower() + "\", already exists with another Niche Shack account. Please use another email address."; } ModelState.AddModelError(error.Code, error.Description); } return(Conflict(ModelState)); } }
public async Task <ActionResult> CreateList(List list) { // Make sure the list name is not empty if (list.Name == null) { return(BadRequest(ModelState)); } // Get the customer id from the access token string customerId = User.FindFirst(ClaimTypes.NameIdentifier).Value; // Create the new list and add it to the database List newList = new List { Id = Guid.NewGuid().ToString("N").ToUpper(), Name = list.Name, Description = list.Description, CollaborateId = Guid.NewGuid().ToString("N").ToUpper() }; unitOfWork.Lists.Add(newList); // Set the owner as the first collaborator of the list ListCollaborator collaborator = new ListCollaborator { Id = Guid.NewGuid(), CustomerId = customerId, ListId = newList.Id, IsOwner = true }; unitOfWork.Collaborators.Add(collaborator); // Save all updates to the database await unitOfWork.Save(); // Return the new list id to the client return(Ok(new { listId = newList.Id })); }
public async Task <ActionResult> AddCollaborator(ItemViewModel itemViewModel) { // Get the customer id string customerId = User.FindFirst(ClaimTypes.NameIdentifier).Value; // Get the list var list = await unitOfWork.Lists.Get(x => x.CollaborateId == itemViewModel.Name, x => new { id = x.Id, name = x.Name }); ListCollaborator collaborator = await unitOfWork.Collaborators.Get(x => x.CustomerId == customerId && x.ListId == list.id); if (collaborator == null) { // Add this customer to the list unitOfWork.Collaborators.Add(new ListCollaborator { CustomerId = customerId, ListId = list.id }); } else { collaborator.IsRemoved = false; unitOfWork.Collaborators.Update(collaborator); } await unitOfWork.Save(); // Setup the email emailService.SetupEmail(SetupAddedCollaboratorEmail, new EmailSetupParams { ListId1 = list.id, Host = GetHost(), CustomerId = customerId }); return(Ok()); }
public async Task <ActionResult> DeleteCollaborator(string customerId, string listId) { // Make sure we are the owner of the list if (!await unitOfWork.Collaborators.Any(x => x.ListId == listId && x.CustomerId == User.FindFirst(ClaimTypes.NameIdentifier).Value&& x.IsOwner)) { return(Unauthorized()); } // Get the collaborator to delete ListCollaborator collaborator = await unitOfWork.Collaborators.Get(x => x.CustomerId == customerId && x.ListId == listId); // If found, delete the collaborator if (collaborator != null) { unitOfWork.Collaborators.Remove(collaborator); await unitOfWork.Save(); return(Ok()); } return(NotFound()); }
public async Task <ActionResult> CreateList(ListData list) { // Get the customer id from the access token string customerId = User.FindFirst(ClaimTypes.NameIdentifier).Value; if (!ModelState.IsValid || list.Name == null) { return(BadRequest(ModelState)); } List newList = new List { Id = Guid.NewGuid().ToString("N").ToUpper(), Name = list.Name, Description = list.Description, CollaborateId = Guid.NewGuid().ToString("N").ToUpper() }; unitOfWork.Repository.Add(newList); ListCollaborator collaborator = new ListCollaborator { Id = Guid.NewGuid(), CustomerId = customerId, ListId = newList.Id, IsOwner = true }; unitOfWork.Repository.Add(collaborator); await unitOfWork.Save(); return(Ok(new { listId = newList.Id })); }