public MarkerViewModel Add(MarkerDto markerDto) { Marker marker = new Marker { Id = markerDto.Id, Description = markerDto.Description, Image = markerDto.Image != null?Convert.FromBase64String(markerDto.Image) : null, Latitude = markerDto.Latitude, Longitude = markerDto.Longitude, CreatedAt = DateTime.Now, Solved = markerDto.Solved, CreatedByCitizenId = _context.Citizens.SingleOrDefault(c => c.Name == markerDto.CreatedByCitizen).Id }; _context.Markers.Add(marker); _context.SaveChanges(); MarkerViewModel markerViewModel = new MarkerViewModel { Id = marker.Id, Description = marker.Description, Latitude = marker.Latitude, Longitude = marker.Longitude, Solved = marker.Solved, CreatedAt = marker.CreatedAt, CreatedByCitizen = marker.CreatedByCitizen.Name, Image = marker.Image }; return(markerViewModel); }
public void Register(RegisterUserDto registerUserDto) { var user = new User { Username = registerUserDto.Username, Password = registerUserDto.Password }; _context.Users.Add(user); var citizen = new Citizen { Name = registerUserDto.Name, UserId = user.Id }; _context.Citizens.Add(citizen); _context.SaveChanges(); }