public IActionResult UpdateArtistMember(int artistId, int artistMemberId, ArtistMember artistMember) { try { if (!ClientKeyIsValid()) { return(Unauthorized()); } if (!UserIsAuthenticatedAndAuthorized(MethodBase.GetCurrentMethod())) { return(Unauthorized()); } if (!UserIsAuthorizedForArtist(artistId)) { return(Unauthorized()); } var invalidArtistPathResult = InvalidArtistPathResult(artistId); if (invalidArtistPathResult != null) { return(invalidArtistPathResult); } var getArtistMemberResult = _getArtistMemberTask.DoTask(artistMemberId); if (getArtistMemberResult.HasException) { return(Error(getArtistMemberResult.Exception)); } if (getArtistMemberResult.HasNoData) { return(NotFound()); } if (getArtistMemberResult.Data.ArtistId != artistId) { return(BadRequest()); } artistMember.ArtistId = artistId; artistMember.Id = artistMemberId; var taskResults = _updateArtistMemberTask.DoTask(artistMember); return(taskResults.Success ? Ok() : Error(taskResults.Exception)); } catch (Exception e) { return(Error(e)); } }
public ArtistMember getArtistMember(int memberId) { ArtistMember result; try { ArtistMember artistMember = this.db.ArtistMembers.Single((ArtistMember a) => a.ArtistMemberId == memberId); result = artistMember; } catch (Exception) { result = new ArtistMember(); } return result; }
public int addArtistMember(ArtistMember member) { int result; try { this.db.ArtistMembers.InsertOnSubmit(member); this.db.SubmitChanges(); result = member.ArtistMemberId; } catch (Exception) { result = -1; } return result; }
public TaskResult <Nothing> DoTask(ArtistMember update) { try { var artistMember = _dbContext.ArtistMembers.SingleOrDefault(am => am.Id == update.Id); if (artistMember == null) { throw new TaskException(SystemMessage("ARTIST_MEMBER_NOT_FOUND")); } var hasEnded = update.EndedOn.HasValue && update.EndedOn.Value <= DateTime.Today; artistMember.StartedOn = update.StartedOn; artistMember.EndedOn = update.EndedOn; artistMember.IsActive = !hasEnded; _dbContext.SaveChanges(); return(new TaskResult <Nothing>(true)); } catch (Exception e) { return(new TaskResult <Nothing>(new TaskException(e))); } }
public IActionResult AddArtistMember(int artistId, ArtistMember artistMember) { try { if (!ClientKeyIsValid()) { return(Unauthorized()); } if (!UserIsAuthenticatedAndAuthorized(MethodBase.GetCurrentMethod())) { return(Unauthorized()); } if (!UserIsAuthorizedForArtist(artistId)) { return(Unauthorized()); } var invalidArtistPathResult = InvalidArtistPathResult(artistId); if (invalidArtistPathResult != null) { return(invalidArtistPathResult); } artistMember.ArtistId = artistId; var taskResults = _addArtistMemberTask.DoTask(artistMember); return(taskResults.Success ? Json(taskResults) : Error(taskResults.Exception)); } catch (Exception e) { return(Error(e)); } }
public TaskResult <int?> DoTask(ArtistMember artistMember) { try { var artistId = artistMember.Artist?.Id ?? artistMember.ArtistId; var personId = artistMember.Member?.Id ?? artistMember.PersonId; var hasEnded = artistMember.EndedOn.HasValue && artistMember.EndedOn.Value <= DateTime.Today; artistMember.Artist = null; artistMember.ArtistId = artistId; artistMember.Member = null; artistMember.PersonId = personId; artistMember.IsActive = !hasEnded; _dbContext.ArtistMembers.Add(artistMember); _dbContext.SaveChanges(); return(new TaskResult <int?>(artistMember.Id)); } catch (Exception e) { return(new TaskResult <int?>(new TaskException(e))); } }
public void TaskSuccessTest() { var addArtistTask = new AddArtist(DbContext, new FormattingService()); var testArtist = TestsModel.Artist; var addArtistResult = addArtistTask.DoTask(testArtist); Assert.IsTrue(addArtistResult.Success); Assert.IsNull(addArtistResult.Exception); Assert.IsNotNull(addArtistResult.Data); var artistId = addArtistResult.Data; Assert.IsNotNull(artistId); Assert.IsTrue(artistId > 0); var addPersonTask = new AddPerson(DbContext, new FormattingService()); var testPerson = TestsModel.Person; var addPersonResult = addPersonTask.DoTask(testPerson); Assert.IsTrue(addPersonResult.Success); Assert.IsNull(addPersonResult.Exception); Assert.IsNotNull(addPersonResult.Data); var memberPerson = testPerson; var artistMember = new ArtistMember { Artist = testArtist, Member = memberPerson, StartedOn = DateTime.Now.AddMonths(-14) }; var task = new AddArtistMember(DbContext); var result = task.DoTask(artistMember); Assert.IsTrue(result.Success); Assert.IsNull(result.Exception); Assert.IsNotNull(result.Data); var listArtistMembersTask = new ListArtistMembers(DbContext); var listArtistMembersResult = listArtistMembersTask.DoTask(testArtist); Assert.IsTrue(listArtistMembersResult.Success); Assert.IsNull(listArtistMembersResult.Exception); Assert.IsNotNull(listArtistMembersResult.Data); var member = listArtistMembersResult.Data.SingleOrDefault(m => m.Id == artistMember.Id); Assert.IsNotNull(member); Assert.AreEqual(artistMember.StartedOn, member.StartedOn); Assert.AreEqual(artistMember.EndedOn, member.EndedOn); Assert.AreEqual(artistMember.IsActive, member.IsActive); var removeArtistTask = new RemoveArtist(DbContext); var removeArtistResult = removeArtistTask.DoTask(testArtist); Assert.IsTrue(removeArtistResult.Success); Assert.IsNull(removeArtistResult.Exception); var removePersonTask = new RemovePerson(DbContext); var removePersonResult = removePersonTask.DoTask(memberPerson); Assert.IsTrue(removePersonResult.Success); Assert.IsNull(removePersonResult.Exception); }
public TaskResult <User> DoTask(UserInvitation userInvitation) { try { var invitation = _dbContext.UserInvitations.Where(ui => ui.Uuid == userInvitation.Uuid) .Include(ui => ui.InvitedByUser) .Single(); if (invitation.Type == UserType.Unassigned) { throw new TaskException(SystemMessage("USER_INVITATION_UNASSIGNED")); } var newUser = userInvitation.CreatedUser; newUser.AuthenticationId = invitation.Email; newUser.Type = invitation.Type; newUser.Roles = invitation.Roles; var newPerson = newUser.Person; newPerson.Email = invitation.Email; var addPersonResult = _addPersonTask.DoTask(newPerson); if (!addPersonResult.Success) { throw addPersonResult.Exception; } var personId = addPersonResult.Data; var proId = newUser.PerformingRightsOrganization?.Id ?? newUser.PerformingRightsOrganizationId; var publisherId = invitation.Publisher?.Id ?? invitation.PublisherId; var recordLabelId = invitation.RecordLabel?.Id ?? invitation.RecordLabelId; var artistId = invitation.Artist?.Id ?? invitation.ArtistId; newUser.Person = null; newUser.PersonId = personId; newUser.PerformingRightsOrganization = null; newUser.PerformingRightsOrganizationId = proId; newUser.Publisher = null; newUser.PublisherId = publisherId; newUser.RecordLabel = null; newUser.RecordLabelId = recordLabelId; _dbContext.Users.Add(newUser); _dbContext.SaveChanges(); invitation.CreatedUser = null; invitation.CreatedUserId = newUser.Id; invitation.AcceptedOn = DateTime.UtcNow; _dbContext.SaveChanges(); invitation.CreatedUser = newUser; if (artistId.HasValue) { var artist = _dbContext.Artists.Single(a => a.Id == artistId.Value); if (invitation.Roles.HasFlag(SystemUserRoles.ArtistMember)) { var artistMember = new ArtistMember { Artist = artist, Member = newPerson, StartedOn = DateTime.Today }; var addArtistMemberResult = _addArtistMember.DoTask(artistMember); if (!addArtistMemberResult.Success) { throw addArtistMemberResult.Exception; } } else if (invitation.Roles.HasFlag(SystemUserRoles.ArtistManager)) { var artistManager = new ArtistManager { Artist = artist, Manager = newPerson, StartedOn = DateTime.Today }; var addArtistManagerResult = _addArtistManager.DoTask(artistManager); if (!addArtistManagerResult.Success) { throw addArtistManagerResult.Exception; } } } newUser.Person = newPerson; newUser.PerformingRightsOrganization = proId > 0 ? _dbContext.PerformingRightsOrganizations.Where(p => p.Id == proId) .Include(p => p.Country) .SingleOrDefault() : null; newUser.Publisher = publisherId > 0 ? _dbContext.Publishers.Where(p => p.Id == publisherId) .Include(p => p.Address).ThenInclude(a => a.Country) .SingleOrDefault() : null; newUser.RecordLabel = recordLabelId > 0 ? _dbContext.RecordLabels.Where(l => l.Id == recordLabelId) .Include(p => p.Address).ThenInclude(a => a.Country) .SingleOrDefault() : null; userInvitation.LoginLink = ApplicationSettings.Web.Domain + WebRoutes.Login; var installation = _getInstallationTask.DoTask(null).Data; var emailTemplate = EmailTemplate($"{invitation.Type}Welcome.html"); var body = ReplaceTokens(emailTemplate, invitation, installation); var subject = ReplaceTokens(_htmlService.GetTitle(emailTemplate), invitation, installation); _emailService.SendEmail(newUser.Person.FirstAndLastName, newUser.Person.Email, installation.Name, ApplicationSettings.Mail.From, subject, body); return(new TaskResult <User>(newUser)); } catch (Exception e) { return(new TaskResult <User>(new TaskException(e))); } }
public ActionResult Processupload(string meta, string uploads) { string[] array = uploads.Split(new char[] { ';' }); string[] array2 = meta.Split(new char[] { '~' }); ArtistRepository artistRepository = new ArtistRepository(new yslDataContext()); Request.Cookies.Get("ysl"); int accountId = 2; DateTime.Now.ToString("MMMM dd, yyyy"); MemberRepository memberRepository = new MemberRepository(new yslDataContext()); ArtistMemberRepository artistMemberRepository = new ArtistMemberRepository(new yslDataContext()); IPhotoRepository photoRepository = new PhotoRepository(new yslDataContext()); string text = array2[1]; text = text.Replace("/temp", ""); string text2 = Server.MapPath(array2[1]); string destFileName = text2.Replace("\\temp", ""); int value = 0; try { System.IO.File.Move(text2, destFileName); value = photoRepository.addPhoto(new Photo { AccountId = accountId, Location = text, Title = "", Description = "" }); } catch { } Artist artist = new Artist { Name = array2[0], PhotoId = new int?(value), Bio = array2[2] }; int artistId = artistRepository.addArtist(artist); string[] array3 = array; for (int i = 0; i < array3.Length; i++) { string text3 = array3[i]; if (!string.IsNullOrWhiteSpace(text3)) { try { Member member = memberRepository.getMember(text3.Trim()); ArtistMember member2 = new ArtistMember { ArtistId = artistId, MemberId = member.MemberId }; artistMemberRepository.addArtistMember(member2); } catch { } } } return RedirectToAction("Index"); }
public void TaskSuccessTest() { var testArtist = TestsModel.Artist; var addArtistTask = new AddArtist(DbContext, new FormattingService()); var addArtistResult = addArtistTask.DoTask(testArtist); Assert.IsTrue(addArtistResult.Success); Assert.IsNull(addArtistResult.Exception); var artistId = addArtistResult.Data; Assert.IsNotNull(artistId); Assert.IsTrue(artistId > 0); var addPersonTask = new AddPerson(DbContext, new FormattingService()); var testPerson = TestsModel.Person; var addPersonResult = addPersonTask.DoTask(testPerson); Assert.IsTrue(addPersonResult.Success); Assert.IsNull(addPersonResult.Exception); Assert.IsNotNull(addPersonResult.Data); var memberPerson = testPerson; var artistMember = new ArtistMember { Artist = testArtist, Member = memberPerson, StartedOn = DateTime.Now.AddMonths(-8) }; var addArtistMemberTask = new AddArtistMember(DbContext); var addArtistMemberResult = addArtistMemberTask.DoTask(artistMember); Assert.IsTrue(addArtistMemberResult.Success); Assert.IsNull(addArtistMemberResult.Exception); Assert.IsNotNull(addArtistMemberResult.Data); var getArtistMemberTask = new GetArtistMember(DbContext); var getArtistMemberResult = getArtistMemberTask.DoTask(artistMember.Id); Assert.IsTrue(getArtistMemberResult.Success); Assert.IsNull(getArtistMemberResult.Exception); Assert.IsNotNull(getArtistMemberResult.Data); var member = getArtistMemberResult.Data; Assert.IsNotNull(member); Assert.AreEqual(artistMember.StartedOn, member.StartedOn); Assert.AreEqual(artistMember.EndedOn, member.EndedOn); Assert.AreEqual(artistMember.IsActive, member.IsActive); member.EndedOn = DateTime.Now.AddDays(-1); var task = new UpdateArtistMember(DbContext); var result = task.DoTask(member); Assert.IsTrue(result.Success); Assert.IsNull(result.Exception); getArtistMemberTask = new GetArtistMember(DbContext); getArtistMemberResult = getArtistMemberTask.DoTask(artistMember.Id); Assert.IsTrue(getArtistMemberResult.Success); Assert.IsNull(getArtistMemberResult.Exception); Assert.IsNotNull(getArtistMemberResult.Data); var updatedMember = getArtistMemberResult.Data; Assert.IsNotNull(updatedMember); Assert.AreEqual(member.StartedOn, updatedMember.StartedOn); Assert.AreEqual(member.EndedOn, updatedMember.EndedOn); Assert.AreEqual(false, updatedMember.IsActive); var removeArtistTask = new RemoveArtist(DbContext); var removeArtistResult = removeArtistTask.DoTask(testArtist); Assert.IsTrue(removeArtistResult.Success); Assert.IsNull(removeArtistResult.Exception); var removePersonTask = new RemovePerson(DbContext); var removePersonResult = removePersonTask.DoTask(memberPerson); Assert.IsTrue(removePersonResult.Success); Assert.IsNull(removePersonResult.Exception); }
public bool updateArtistMember(ArtistMember member) { throw new NotImplementedException(); }