public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { var organisation = new Domain.Organisation { Id = request.Id, name = request.name, description = request.description, }; _context.Organisations.Add(organisation); var user = await _context.Users.SingleOrDefaultAsync(x => x.UserName == _userAccessor.GetCurrentUsername()); var admin = new UserOrganisationAdmin { AppUser = user, Organisation = organisation, orgAdmin = true }; _context.UserOrganisationAdmins.Add(admin); var success = await _context.SaveChangesAsync() > 0; if (success) { return(Unit.Value); } throw new Exception("Problem saving changes"); }
public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { var course = new Domain.Course { Id = request.Id, navn = request.navn, beskrivelse = request.beskrivelse, }; _context.Courses.Add(course); var user = await _context.Users.SingleOrDefaultAsync(x => x.UserName == _userAccessor.GetCurrentUsername()); /*var admin = new UserCourse * { * AppUser = user, * Course = course, * CourseAdmin = true, * DateJoined = DateTime.Now * }; * * _context.UserCourses.Add(admin);*/ var success = await _context.SaveChangesAsync() > 0; if (success) { return(Unit.Value); } throw new Exception("Problem saving changes"); }
public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { var user = await _context.Users.SingleOrDefaultAsync(x => x.UserName == _userAccessor.GetCurrentUsername()); if (user.ProfilePhoto == null) { throw new RestException(HttpStatusCode.NotFound, new { photo = "Not Found" }); } var result = _photoAccessor.DeletePhoto(user.ProfilePhoto.Id); if (result == null) { throw new Exception("Problem delelting the photo"); } user.ProfilePhoto = null; var success = await _context.SaveChangesAsync() > 0; if (success) { return(Unit.Value); } throw new Exception("problem saving changes"); }
public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { var group = new Domain.Group { Id = request.Id, navn = request.navn, beskrivelse = request.beskrivelse, aktiv = request.aktiv, aktiv_til_og_med = request.aktiv_til_og_med, opprettet = request.opprettet, groupType = request.groupType, OrganisationId = request.organisation }; _context.Groups.Add(group); var user = await _context.Users.SingleOrDefaultAsync(x => x.UserName == _userAccessor.GetCurrentUsername()); var admin = new UserGroup { AppUser = user, Group = group, GroupAdmin = true, DateJoined = DateTime.Now }; _context.UserGroups.Add(admin); var success = await _context.SaveChangesAsync() > 0; if (success) { return(Unit.Value); } throw new Exception("Problem saving changes"); }
public async Task <Photo> Handle(Command request, CancellationToken cancellationToken) { var photoUploadResult = _photoAccessor.AddPhoto(request.File); var user = await _context.Users.SingleOrDefaultAsync(x => x.UserName == _userAccessor.GetCurrentUsername()); var photo = new Photo { Url = photoUploadResult.Url, Id = photoUploadResult.PublicId }; user.ProfilePhoto = photo; var success = await _context.SaveChangesAsync() > 0; if (success) { return(photo); } throw new Exception("problem saving changes"); }
public async Task <UserDto> Handle(Query request, CancellationToken cancellationToken) { var user = await _userManager.FindByNameAsync(_userAccessor.GetCurrentUsername()); return(_mapper.Map <AppUser, UserDto>(user)); }