public async Task <IActionResult> UpdateBadge(Guid id, Badge badge) { var badgeToUpdate = await _context.Badges.FirstOrDefaultAsync(x => x.Id == id); if (badgeToUpdate.Id != badge.Id) { throw new Exception("Id-update is not allowed"); } badgeToUpdate.Name = badge.Name; badgeToUpdate.Icon = badge.Icon; badgeToUpdate.Description = badge.Description; _context.Entry(badge).State = EntityState.Modified; await _context.SaveChangesAsync(); return(NoContent()); }
public async Task <Unit> Handle(UpdateMakerSpace request, CancellationToken cancellationToken) { var makerspace = await _context.MakerSpace.Include(x => x.Address).Include(x => x.ContactInfo).FirstOrDefaultAsync(x => x.Id == request.Id); makerspace.UpdateMakerSpace(request); _context.Entry(makerspace).State = EntityState.Modified; await _context.SaveChangesAsync(); return(new Unit()); }
public async Task <Unit> Handle(UpdateMakerSpaceTool request, CancellationToken cancellationToken) { var tool = await _context.Set <Tool>().FirstOrDefaultAsync(x => x.Id == request.Id); tool.UpdateTool(request); _context.Entry(tool).State = EntityState.Modified; await _context.SaveChangesAsync(); return(new Unit()); }
public async Task <Unit> Handle(UpdateUser request, CancellationToken cancellationToken) { var user = await _context.Users.FindAsync(request.Id); user.UpdateUserFromRequest(request); _context.Entry(user).State = EntityState.Modified; await _context.SaveChangesAsync(); return(new Unit()); }
public async Task <IActionResult> UserFollowsMakerSpace(Guid userId, Guid makerspaceId) { var user = await _context.Users.Include(x => x.MakerSpaces).FirstOrDefaultAsync(x => x.Id == userId); var ms = await _context.MakerSpace.FirstOrDefaultAsync(x => x.Id == makerspaceId); if (user is null || ms is null) { return(NotFound()); } if (user.MakerSpaces.Contains(ms)) { return(NotFound("User already follows makerspace")); } user.MakerSpaces.Add(ms); _context.Entry(user).State = EntityState.Modified; await _context.SaveChangesAsync(); return(Accepted()); }
public async Task <IActionResult> UpdateEvent(Guid eventId, Event newEvent) { var existingEvent = await _context.Events.FirstOrDefaultAsync(x => x.Id == eventId); existingEvent.Address = newEvent.Address; existingEvent.Title = newEvent.Title; existingEvent.Start = newEvent.Start; existingEvent.End = newEvent.End; existingEvent.Description = newEvent.Description; existingEvent.Badge = newEvent.Badge; _context.Entry(existingEvent).State = EntityState.Modified; await _context.SaveChangesAsync(); return(NoContent()); }